Repository URL to install this package:
|
Version:
3.7.2 ▾
|
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const exotic_1 = require("exotic");
const mobx_1 = require("xmobx/mobx");
const deps_1 = require("../deps");
let identifierIndex = 0;
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 deps_1.serializeListIntoMergedObj(this.inputsList);
}
// ============ compat ============
/**
* @todo here, key is we need to finish FieldSet to recurse with FieldSet
*/
get(identifier) {
const isInputWeAreLookingFor = (inputState) => {
if (exotic_1.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([
mobx_1.observable.ref
], FormState.prototype, "inputsList", void 0);
tslib_1.__decorate([
mobx_1.observable.ref
], FormState.prototype, "inputPluginsList", void 0);
tslib_1.__decorate([
mobx_1.action
], FormState.prototype, "setInputsList", null);
tslib_1.__decorate([
mobx_1.action
], FormState.prototype, "setInputPluginsList", null);
tslib_1.__decorate([
mobx_1.action
], FormState.prototype, "setIdentifier", null);
tslib_1.__decorate([
mobx_1.computed
], FormState.prototype, "isValid", null);
exports.FormState = FormState;
//# sourceMappingURL=FormState.js.map