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/forms / build / dist / new-forms / forms / FormState.js
Size: Mime:
import * as tslib_1 from "tslib";
import { isFunction } from 'exotic';
import { observable, action, computed } from 'xmobx/mobx';
import { serializeListIntoMergedObj } from '../deps';
let identifierIndex = 0;
export class FormState {
    constructor() {
        this.identifier = 'form-' + identifierIndex++;
        this.inputsList = [];
        this.inputPluginsList = [];
    }
    setInputsList(inputsList) {
        inputsList.forEach(input => {
            input.setFormState(this);
        });
        this.inputsList = inputsList;
    }
    setInputPluginsList(list) {
        this.inputPluginsList = list;
    }
    setIdentifier(identifier) {
        this.identifier = identifier;
    }
    toJSON() {
        return serializeListIntoMergedObj(this.inputsList);
    }
    // ============ compat ============
    /**
     * @todo here, key is we need to finish FieldSet to recurse with FieldSet
     */
    get(identifier) {
        const isInputWeAreLookingFor = (inputState) => {
            if (isFunction(identifier)) {
                return identifier(inputState);
            }
            else {
                return inputState.identifier === identifier;
            }
        };
        return this.inputsList.find(isInputWeAreLookingFor);
    }
    get isValid() {
        return this.inputsList.every(inputState => inputState.isValid);
    }
}
tslib_1.__decorate([
    observable.ref
], FormState.prototype, "inputsList", void 0);
tslib_1.__decorate([
    observable.ref
], FormState.prototype, "inputPluginsList", void 0);
tslib_1.__decorate([
    action
], FormState.prototype, "setInputsList", null);
tslib_1.__decorate([
    action
], FormState.prototype, "setInputPluginsList", null);
tslib_1.__decorate([
    action
], FormState.prototype, "setIdentifier", null);
tslib_1.__decorate([
    computed
], FormState.prototype, "isValid", null);
//# sourceMappingURL=FormState.js.map