Comparing version 0.6.0 to 0.7.0
@@ -122,1 +122,20 @@ /** A truthy string or falsy values */ | ||
} | ||
/** Each item in the array is a validatable */ | ||
export declare type ValidatableArray = Validatable<any>[]; | ||
/** | ||
* Makes it easier to work with dynamically maintained array | ||
*/ | ||
export declare class FormStateLazy<TValue extends ValidatableArray> implements Validatable<TValue> { | ||
/** It is a function as fields can change over time */ | ||
private getFields; | ||
readonly $: TValue; | ||
constructor( | ||
/** It is a function as fields can change over time */ | ||
getFields: () => TValue); | ||
validating: boolean; | ||
validate(): Promise<{ | ||
hasError: boolean; | ||
}>; | ||
readonly hasError: boolean; | ||
readonly error: string; | ||
} |
@@ -287,1 +287,59 @@ "use strict"; | ||
exports.FormState = FormState; | ||
/** | ||
* Makes it easier to work with dynamically maintained array | ||
*/ | ||
var FormStateLazy = (function () { | ||
function FormStateLazy( | ||
/** It is a function as fields can change over time */ | ||
getFields) { | ||
this.getFields = getFields; | ||
this.validating = false; | ||
} | ||
Object.defineProperty(FormStateLazy.prototype, "$", { | ||
get: function () { | ||
return this.getFields(); | ||
}, | ||
enumerable: true, | ||
configurable: true | ||
}); | ||
FormStateLazy.prototype.validate = function () { | ||
var _this = this; | ||
this.validating = true; | ||
return Promise.all(this.getFields().map(function (value) { return value.validate(); })).then(function (res) { | ||
_this.validating = false; | ||
return { hasError: _this.hasError }; | ||
}); | ||
}; | ||
Object.defineProperty(FormStateLazy.prototype, "hasError", { | ||
get: function () { | ||
return this.getFields().some(function (f) { return f.hasError; }); | ||
}, | ||
enumerable: true, | ||
configurable: true | ||
}); | ||
Object.defineProperty(FormStateLazy.prototype, "error", { | ||
get: function () { | ||
var subItemWithError = this.getFields().find(function (f) { return !!f.hasError; }); | ||
return subItemWithError.error; | ||
}, | ||
enumerable: true, | ||
configurable: true | ||
}); | ||
return FormStateLazy; | ||
}()); | ||
__decorate([ | ||
mobx_1.computed | ||
], FormStateLazy.prototype, "$", null); | ||
__decorate([ | ||
mobx_1.observable | ||
], FormStateLazy.prototype, "validating", void 0); | ||
__decorate([ | ||
mobx_1.action | ||
], FormStateLazy.prototype, "validate", null); | ||
__decorate([ | ||
mobx_1.computed | ||
], FormStateLazy.prototype, "hasError", null); | ||
__decorate([ | ||
mobx_1.computed | ||
], FormStateLazy.prototype, "error", null); | ||
exports.FormStateLazy = FormStateLazy; |
{ | ||
"name": "formstate", | ||
"version": "0.6.0", | ||
"version": "0.7.0", | ||
"description": "Painless and simple MobX form management", | ||
@@ -5,0 +5,0 @@ "main": "./lib/index.js", |
@@ -276,1 +276,37 @@ import { observable, action, computed } from 'mobx'; | ||
} | ||
/** Each item in the array is a validatable */ | ||
export type ValidatableArray = Validatable<any>[]; | ||
/** | ||
* Makes it easier to work with dynamically maintained array | ||
*/ | ||
export class FormStateLazy<TValue extends ValidatableArray> implements Validatable<TValue> { | ||
@computed get $() { | ||
return this.getFields(); | ||
} | ||
constructor( | ||
/** It is a function as fields can change over time */ | ||
private getFields: () => TValue | ||
) { } | ||
@observable validating = false; | ||
@action validate() { | ||
this.validating = true; | ||
return Promise.all(this.getFields().map((value) => value.validate())).then((res) => { | ||
this.validating = false; | ||
return { hasError: this.hasError }; | ||
}) | ||
} | ||
@computed get hasError() { | ||
return this.getFields().some(f => f.hasError); | ||
} | ||
@computed get error() { | ||
const subItemWithError = this.getFields().find(f => !!f.hasError); | ||
return subItemWithError.error; | ||
} | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
30203
856