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    
ui-component-library / dist / forms / input / InputChain.js
Size: Mime:
"use strict";
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 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;
    }
}
exports.InputChain = InputChain;
exports.default = InputChain;
//# sourceMappingURL=InputChain.js.map