Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
@skava/ui / dist / forms / input / InputChain.js
Size: Mime:
"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});

const tslib_1 = require("tslib");
/* eslint-disable brace-style */


const react_1 = tslib_1.__importDefault(require("react"));

const exotic_1 = require("exotic");

const mobx_1 = require("xmobx/mobx"); // @todo import from proper place @@perf @dupe


const isReactProps = props => Object.isExtensible(props) === false;
/**
 * @todo the input should have the aria-error props and that should be tested in a unit test
 */


class InputChain extends react_1.default.Component {
  constructor() {
    // static isSatisfiedByProps(props: Props): boolean {
    //   return true
    // }
    // validate(): void {}
    super(...arguments); // @note - these were in ReactChain - flattening inheritence

    this.store = new Map(Object.entries({
      props: exotic_1.EMPTY_OBJ,
      state: exotic_1.EMPTY_OBJ
    }));
  }

  get(key) {
    return this.store.get(key);
  }

  has(key) {
    return this.store.has(key);
  }

  clear() {
    this.store.clear();
    return this;
  }

  set(key, value) {
    this.store.set(key, value);
    return this;
  }

  delete(key) {
    this.store.delete(key);
    return this;
  }

  merge(obj) {
    Object.keys(obj).forEach(key => {
      let val = obj[key];

      if (this.has(key)) {
        val = [this.get(key), val];
      }

      return this.set(key, val);
    });
    return this;
  }

  entries() {
    return exotic_1.fromCollectionToObj(this.store);
  }
  /**
   * @note - had to change to this for testing & react warnings
   * @note - make sure it's always an object
   */


  setPluginState(state) {
    if (exotic_1.isObj(state) === false) {
      console.warn('tried to set non object `state` in `InputChain` - expand for stack trace');
      return this.store.set('state', {});
    } else {
      return this.store.set('state', state);
    }
  }
  /**
   * @action
   */


  setPluginProps(props) {
    if (exotic_1.isObj(props) === false) {
      // @todo default to EMPTY_OBJ?
      console.warn('tried to set non object `props` in `InputChain` - expand for stack trace');
      return this.store.set('props', {});
    } else {
      return this.store.set('props', props);
    }
  }
  /**
   * @action
   */


  set isValid(isValid) {
    // hm, will also  put  on state
    this.set('isValid', isValid);
    this.get('state').isValidInput = isValid;
  }
  /**
   * may also want to do relational
   *
   * @sriaarthi
   * @example
   *  - this can be done the same with `isEnabled`
   *    and would allow only being enabled once
   *    this.parent.get('add-to-account').isSelected
   */


  get isValid() {
    const isValidInput = this.get('state').isValidInput;
    return isValidInput;
  }
  /**
   * === added these since they were commmon ===
   */

  /**
   * @computed
   */


  get type() {
    return this.get('state').value || this.get('props').value;
  }
  /**
   * @action
   */


  setValue(value) {
    this.get('state').value = value; // return this
  }
  /**
   * @computed
   */


  getValue() {
    return this.get('state').value;
  }

}

tslib_1.__decorate([mobx_1.action.bound], InputChain.prototype, "setValue", null);

exports.InputChain = InputChain;
exports.default = InputChain; //# sourceMappingURL=InputChain.js.map