Repository URL to install this package:
|
Version:
3.5.4-es ▾
|
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