How to use the ember-changeset/utils/is-changeset function in ember-changeset

To help you get started, we’ve selected a few ember-changeset 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 hummingbird-me / hummingbird-client / app / components / library-entry / state.js View on Github external
* perform(content) {
      // Warning: semi-private e-c API
      const owner = get(this, 'owner');
      const libraryEntry = content || get(owner, 'libraryEntry');
      // Send the task to the onUpdate function
      get(owner, 'onUpdate')(libraryEntry, this);
      try {
        yield libraryEntry.save();
        get(owner, 'queryCache').invalidateType('library-entry');
      } catch (error) {
        if (isChangeset(libraryEntry)) {
          libraryEntry.rollback();
        } else {
          libraryEntry.rollbackAttributes();
        }
        throw error;
      }
    }
  }).enqueue(),
github poteto / ember-changeset / addon / helpers / changeset.ts View on Github external
export function changeset(
  [obj, validations]: [object | Promise, ValidatorFunc],
  options: Config = {}
): Changeset | Promise {
  if (isChangeset(obj)) {
    return obj;
  }

  if (isPromise(obj)) {
    return Promise.resolve(obj).then((resolved: any) => new Changeset(resolved, validations, {}, options));
  }

  return new Changeset(obj, validations, {}, options);
}
github poteto / ember-changeset / addon / index.js View on Github external
merge(
      changeset /*: ChangesetDef */
    ) /*: ChangesetDef */ {
      let content /*: Object */ = get(this, CONTENT);
      assert('Cannot merge with a non-changeset', isChangeset(changeset));
      assert('Cannot merge with a changeset of different content', get(changeset, CONTENT) === content);

      if (get(this, 'isPristine') && get(changeset, 'isPristine')) {
        return this;
      }

      let c1 /*: Changes    */ = get(this, CHANGES);
      let c2 /*: Changes    */ = get(changeset, CHANGES);
      let e1 /*: Errors     */ = get(this, ERRORS);
      let e2 /*: Errors     */ = get(changeset, ERRORS);

      let newChangeset  /*: ChangesetDef */ = new Changeset(content, get(this, VALIDATOR));
      let newErrors     /*: Errors  */      = objectWithout(keys(c2), e1);
      let newChanges    /*: Changes */      = objectWithout(keys(e2), c1);
      let mergedErrors  /*: Errors  */      = mergeNested(newErrors, e2);
      let mergedChanges /*: Changes */      = mergeNested(newChanges, c2);