How to use the datx.updateModel function in datx

To help you get started, we’ve selected a few datx examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github infinum / datx / packages / datx-jsonapi / src / Response.ts View on Github external
const record: PureModel = this.data as PureModel;
    if (record === data) {
      return this;
    }

    const newId = getModelId(record);
    const type = getModelType(record);

    const viewIndexes = this.views.map((view) => view.list.indexOf(record));

    if (this.__collection) {
      this.__collection.removeOne(type, newId);
      this.__collection.add(data);
    }

    updateModel(data, modelToJSON(record));
    updateModelId(data, newId);

    this.views.forEach((view, index) => {
      if (viewIndexes[index] !== -1) {
        view.list[viewIndexes[index]] = data;
      }
    });

    return new Response(this.__response, this.__collection, this.__options, data);
  }
github infinum / datx / packages / datx-jsonapi / src / decorateCollection.ts View on Github external
private __addRecord(obj: IRecord): IJsonapiModel {
      const staticCollection = this.constructor as typeof Collection;
      const {type, id} = obj;
      let record: IJsonapiModel = this.find(type, id) as IJsonapiModel;
      const flattened: IRawModel = flattenModel(obj);

      if (record) {
        updateModel(record, flattened);
      } else if (staticCollection.types.filter((item) => item.type === obj.type).length) {
        record = this.add(flattened, obj.type) as IJsonapiModel;
      } else {
        record = this.add(new Model(flattened));
      }

      return record;
    }