How to use the ember-changeset/utils/is-object 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 poteto / ember-changeset / addon / index.js View on Github external
addError /*:: > */ (
      key   /*: string */,
      error /*: T      */
    ) /*: T */ {
      // Construct new `Err` instance.
      let newError /*: Err */;
      if (isObject(error)) {
        let errorLike /*: ErrLike<*> */ = (error /*: any */);
        assert('Error must have value.', errorLike.hasOwnProperty('value'));
        assert('Error must have validation.', errorLike.hasOwnProperty('validation'));
        newError = new Err(errorLike.value, errorLike.validation);
      } else {
        let validation /*: ValidationErr */ = (error /*: any */);
        newError = new Err(get(this, key), validation);
      }

      // Remove `key` from changes map.
      let c = (this /*: ChangesetDef */);

      // Add `key` to errors map.
      let errors /*: Errors */ = get(this, ERRORS);
      setNestedProperty(errors, key, newError);
      c.notifyPropertyChange(ERRORS);
github poteto / ember-changeset / addon / utils / computed / inflate.ts View on Github external
key.split('.').forEach((_part, i, allParts) => {
          if (i < allParts.length - 1) {
            let path = allParts.slice(0, i+1).join('.');
            let msg = `Path ${path} leading up to ${key} must be an Object if specified.`;
            assert(msg, isObject(obj[path]) || isBlank(obj[path]));
          }
        });
      });
github poteto / ember-changeset / addon / utils / computed / object-to-array.ts View on Github external
return keys(obj).map(key => {
      let value = transform(obj[key]);

      if (flattenObjects && isObject(value)) {
        return assign({ key }, value);
      }

      return { key, value };
    })
  }).readOnly();
github poteto / ember-changeset / addon / index.js View on Github external
prepare(
      prepareChangesFn /*: ({ [string]: mixed }) => ({ [string]: mixed }) */
    ) /*: ChangesetDef */ {
      let changes /*: { [string]: mixed } */ = get(this, '_bareChanges');
      let preparedChanges = prepareChangesFn(changes);

      assert('Callback to `changeset.prepare` must return an object', isObject(preparedChanges));
      validateNestedObj('preparedChanges', preparedChanges);

      let newChanges /*: Changes */ = keys(preparedChanges).reduce((newObj, key) => {
        newObj[key] = new Change(preparedChanges[key]);
        return newObj;
      }, {});

      set(this, CHANGES, newChanges);
      return this;
    },