How to use the ember-changeset/-private/err 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);

      // Notify that `key` has changed.
      c.notifyPropertyChange(key);
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);

      // Notify that `key` has changed.
      c.notifyPropertyChange(key);

      // Return passed-in `error`.
      return error;
    },
github poteto / ember-changeset / addon / index.js View on Github external
let newErrors /*: Errors */ = keys(errors).reduce((newObj, key) => {
        let e /*: ErrLike<*> */ = errors[key];
        newObj[key] = new Err(e.value, e.validation);
        return newObj;
      }, {});
github poteto / ember-changeset / addon / index.js View on Github external
pushErrors(
      key          /*: string        */,
      ...newErrors /*: Array */
    ) /*: ErrLike */ {
      let errors /*: Errors */ = get(this, ERRORS);
      let existingError /*: Err */ = errors[key] || new Err(null, []);
      let validation /*: ValidationErr */ = existingError.validation;
      let value /*: mixed */ = get(this, key);

      if (!isArray(validation) && isPresent(validation)) {
        let v /*: string */ = (existingError.validation /*: any */);
        existingError.validation = [v];
      }

      let v /*: Array */ = (existingError.validation /*: any */);
      validation = [...v, ...newErrors];

      let c = (this /*: ChangesetDef */)
      c.notifyPropertyChange(ERRORS);
      c.notifyPropertyChange(key);

      errors[key] = new Err(value, validation);
github poteto / ember-changeset / addon / index.js View on Github external
let validation /*: ValidationErr */ = existingError.validation;
      let value /*: mixed */ = get(this, key);

      if (!isArray(validation) && isPresent(validation)) {
        let v /*: string */ = (existingError.validation /*: any */);
        existingError.validation = [v];
      }

      let v /*: Array */ = (existingError.validation /*: any */);
      validation = [...v, ...newErrors];

      let c = (this /*: ChangesetDef */)
      c.notifyPropertyChange(ERRORS);
      c.notifyPropertyChange(key);

      errors[key] = new Err(value, validation);
      return { value, validation };
    },