How to use the datx-utils.warn function in datx-utils

To help you get started, we’ve selected a few datx-utils 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 / src / helpers / model / fields.ts View on Github external
function backRefChange(model: PureModel, key: string, change: IArrayChange, refOptions: IReferenceOptions) {
  const property = refOptions.property as string;
  const oldValue = model[key].length > change.index ? model[key][change.index] : null;
  if (change.newValue) {
    modelAddReference(change.newValue, property, model);
  }
  if (oldValue) {
    modelRemoveReference(oldValue, property, model);
  }

  warn(`This shouldn't have happened. Please open an issue: https://github.com/infinum/datx/issues/new`);

  return null;
}
github infinum / datx / packages / datx / src / helpers / model / utils.ts View on Github external
export function cloneModel(model: T): T {
  const TypeModel = model.constructor as typeof PureModel;
  const rawData = modelToJSON(model);
  const meta = rawData[META_FIELD] || { };
  meta.originalId = meta.id;
  delete meta.id;

  const clone = new TypeModel(rawData) as T;

  const collection = getModelCollection(model);
  if (collection) {
    collection.add(clone);
  } else {
    warn(`The model is not in the collection. Referencing the original model won't be possible`);
  }

  return clone;
}

datx-utils

DatX lib utils for mixins

MIT
Latest version published 4 years ago

Package Health Score

57 / 100
Full package analysis