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 / src / forms / input / InputChain.js
Size: Mime:
"use strict";

var __decorate = this && this.__decorate || function (decorators, target, key, desc) {
  var c = arguments.length,
      r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc,
      d;
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
  return c > 3 && r && Object.defineProperty(target, key, r), r;
};

var __importDefault = this && this.__importDefault || function (mod) {
  return mod && mod.__esModule ? mod : {
    "default": mod
  };
};

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

const exotic_1 = require("exotic");

const mobx_1 = require("xmobx/mobx");

const ReactChain_1 = __importDefault(require("./ReactChain")); // @todo import from proper place


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 ReactChain_1.default {
  constructor(parent) {
    // @todo arguments.length?
    if (isReactProps(parent)) {
      super(parent);
    } else {
      super(exotic_1.EMPTY_OBJ);
    }

    this.parent = parent;
    this.store = new Map();
    this.store.set('props', exotic_1.EMPTY_OBJ);
    this.store.set('state', exotic_1.EMPTY_OBJ);
  }

  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;
  }

}

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

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