Comparing version 2.0.0 to 2.1.0
@@ -0,1 +1,4 @@ | ||
# 2.1.0 | ||
* Refactor arrow functions to be on the prototype as requested by MobX. [ref](https://github.com/formstate/formstate/pull/82) | ||
# 2.0.0 | ||
@@ -2,0 +5,0 @@ * BREAKING: Minimum Requirement for MobX is now version 6. This is enforced by `peerDependencies`. |
@@ -38,6 +38,6 @@ import { ComposibleValidatable, Validator } from './types'; | ||
setAutoValidationDefault: (autoValidationDefault: boolean) => this; | ||
getAutoValidationDefault: () => boolean; | ||
getAutoValidationDefault(): boolean; | ||
protected _autoValidationEnabled: boolean; | ||
enableAutoValidation: () => this; | ||
enableAutoValidationAndValidate: () => Promise<{ | ||
enableAutoValidation(): this; | ||
enableAutoValidationAndValidate(): Promise<{ | ||
hasError: true; | ||
@@ -48,3 +48,3 @@ } | { | ||
}>; | ||
disableAutoValidation: () => this; | ||
disableAutoValidation(): this; | ||
constructor(_initValue: TValue); | ||
@@ -59,4 +59,4 @@ protected _validators: Validator<TValue>[]; | ||
*/ | ||
onUpdate: (handler: (state: FieldState<TValue>) => any) => this; | ||
protected executeOnUpdate: () => void; | ||
onUpdate(handler: (state: FieldState<TValue>) => any): this; | ||
protected executeOnUpdate(): void; | ||
/** | ||
@@ -69,11 +69,11 @@ * Allows you to take actions in your code based on `value` changes caused by user interactions | ||
}) => any; | ||
onDidChange: (handler: (config: { | ||
onDidChange(handler: (config: { | ||
newValue: TValue; | ||
oldValue: TValue; | ||
}) => any) => this; | ||
protected executeOnDidChange: (config: { | ||
}) => any): this; | ||
protected executeOnDidChange(config: { | ||
newValue: TValue; | ||
oldValue: TValue; | ||
}) => void; | ||
setAutoValidationDebouncedMs: (milliseconds: number) => this; | ||
}): void; | ||
setAutoValidationDebouncedMs(milliseconds: number): this; | ||
/** Trackers for validation */ | ||
@@ -83,3 +83,3 @@ protected lastValidationRequest: number; | ||
/** On change on the component side */ | ||
onChange: (value: TValue) => void; | ||
onChange(value: TValue): void; | ||
/** | ||
@@ -89,3 +89,3 @@ * If the page wants to reinitialize the field, | ||
*/ | ||
reset: (value?: TValue) => void; | ||
reset(value?: TValue): void; | ||
get hasError(): boolean; | ||
@@ -96,3 +96,3 @@ validating: boolean; | ||
*/ | ||
validate: () => Promise<{ | ||
validate(): Promise<{ | ||
hasError: true; | ||
@@ -103,3 +103,3 @@ } | { | ||
}>; | ||
queuedValidationWakeup: () => void; | ||
queuedValidationWakeup(): void; | ||
/** | ||
@@ -106,0 +106,0 @@ * Runs validation with debouncing to keep the UI super smoothly responsive |
@@ -81,8 +81,2 @@ "use strict"; | ||
}); | ||
Object.defineProperty(this, "getAutoValidationDefault", { | ||
enumerable: true, | ||
configurable: true, | ||
writable: true, | ||
value: function () { return _this._autoValidationDefault; } | ||
}); | ||
Object.defineProperty(this, "_autoValidationEnabled", { | ||
@@ -94,29 +88,2 @@ enumerable: true, | ||
}); | ||
Object.defineProperty(this, "enableAutoValidation", { | ||
enumerable: true, | ||
configurable: true, | ||
writable: true, | ||
value: function () { | ||
_this._autoValidationEnabled = true; | ||
return _this; | ||
} | ||
}); | ||
Object.defineProperty(this, "enableAutoValidationAndValidate", { | ||
enumerable: true, | ||
configurable: true, | ||
writable: true, | ||
value: function () { | ||
_this._autoValidationEnabled = true; | ||
return _this.validate(); | ||
} | ||
}); | ||
Object.defineProperty(this, "disableAutoValidation", { | ||
enumerable: true, | ||
configurable: true, | ||
writable: true, | ||
value: function () { | ||
_this._autoValidationEnabled = false; | ||
return _this; | ||
} | ||
}); | ||
Object.defineProperty(this, "_validators", { | ||
@@ -148,24 +115,2 @@ enumerable: true, | ||
/** | ||
* onUpdate is called whenever we change something in our local state that is significant | ||
* - any validation() call | ||
* - any reset() call | ||
*/ | ||
Object.defineProperty(this, "onUpdate", { | ||
enumerable: true, | ||
configurable: true, | ||
writable: true, | ||
value: function (handler) { | ||
_this._onUpdate = handler; | ||
return _this; | ||
} | ||
}); | ||
Object.defineProperty(this, "executeOnUpdate", { | ||
enumerable: true, | ||
configurable: true, | ||
writable: true, | ||
value: function () { | ||
_this._onUpdate && _this._onUpdate(_this); | ||
} | ||
}); | ||
/** | ||
* Allows you to take actions in your code based on `value` changes caused by user interactions | ||
@@ -179,28 +124,2 @@ */ | ||
}); | ||
Object.defineProperty(this, "onDidChange", { | ||
enumerable: true, | ||
configurable: true, | ||
writable: true, | ||
value: function (handler) { | ||
_this._onDidChange = handler; | ||
return _this; | ||
} | ||
}); | ||
Object.defineProperty(this, "executeOnDidChange", { | ||
enumerable: true, | ||
configurable: true, | ||
writable: true, | ||
value: function (config) { | ||
_this._onDidChange && _this._onDidChange(config); | ||
} | ||
}); | ||
Object.defineProperty(this, "setAutoValidationDebouncedMs", { | ||
enumerable: true, | ||
configurable: true, | ||
writable: true, | ||
value: function (milliseconds) { | ||
_this.queueValidation = mobx_1.action(utils_1.debounce(_this.queuedValidationWakeup, milliseconds)); | ||
return _this; | ||
} | ||
}); | ||
/** Trackers for validation */ | ||
@@ -219,46 +138,2 @@ Object.defineProperty(this, "lastValidationRequest", { | ||
}); | ||
/** On change on the component side */ | ||
Object.defineProperty(this, "onChange", { | ||
enumerable: true, | ||
configurable: true, | ||
writable: true, | ||
value: function (value) { | ||
// no long prevent any debounced validation request | ||
_this.preventNextQueuedValidation = false; | ||
// Store local old value for onDidChange | ||
var oldValue = _this.value; | ||
// Immediately set for local ui binding | ||
_this.value = value; | ||
// Call on did change if any | ||
_this.executeOnDidChange({ newValue: value, oldValue: oldValue }); | ||
_this.dirty = true; | ||
_this.executeOnUpdate(); | ||
if (_this._autoValidationEnabled) { | ||
_this.queueValidation(); | ||
} | ||
} | ||
}); | ||
/** | ||
* If the page wants to reinitialize the field, | ||
* it should call this function | ||
*/ | ||
Object.defineProperty(this, "reset", { | ||
enumerable: true, | ||
configurable: true, | ||
writable: true, | ||
value: function (value) { | ||
if (value === void 0) { value = _this._initValue; } | ||
// If a previous validation comes back ignore it | ||
_this.preventNextQueuedValidation = true; | ||
// This value vetos all previous values | ||
_this._autoValidationEnabled = _this._autoValidationDefault; | ||
_this.value = value; | ||
_this.error = undefined; | ||
_this.dirty = false; | ||
_this.hasBeenValidated = false; | ||
_this.$ = value; | ||
_this._on$Reinit(); | ||
_this.executeOnUpdate(); | ||
} | ||
}); | ||
Object.defineProperty(this, "validating", { | ||
@@ -271,75 +146,2 @@ enumerable: true, | ||
/** | ||
* Runs validation on the current value immediately | ||
*/ | ||
Object.defineProperty(this, "validate", { | ||
enumerable: true, | ||
configurable: true, | ||
writable: true, | ||
value: function () { | ||
_this.lastValidationRequest++; | ||
var lastValidationRequest = _this.lastValidationRequest; | ||
_this.validating = true; | ||
var value = _this.value; | ||
return types_1.applyValidators(_this.value, _this._validators || []) | ||
.then(mobx_1.action(function (fieldError) { | ||
/** | ||
* If validation comes back out of order then the result of this validation is not siginificant | ||
* We simply copy the value from the last validation attempt | ||
*/ | ||
if (_this.lastValidationRequest !== lastValidationRequest) { | ||
if (_this.hasError) { | ||
return { hasError: true }; | ||
} | ||
else { | ||
return { | ||
hasError: false, | ||
value: _this.$, | ||
}; | ||
} | ||
} | ||
_this.validating = false; | ||
_this.hasBeenValidated = true; | ||
/** For any change in field error, update our error */ | ||
if (fieldError != _this.error) { | ||
_this.error = fieldError; | ||
} | ||
/** Check for error */ | ||
var hasError = _this.hasError; | ||
/** If no error */ | ||
if (!hasError) { | ||
/** Copy over the value to validated value */ | ||
if (_this.$ !== value) { | ||
_this.$ = value; | ||
} | ||
/** Trigger any form level validations if required */ | ||
_this._on$ValidationPass(); | ||
} | ||
/** before returning update */ | ||
_this.executeOnUpdate(); | ||
/** return a result based on error status */ | ||
if (hasError) { | ||
return { hasError: true }; | ||
} | ||
else { | ||
return { | ||
hasError: false, | ||
value: value | ||
}; | ||
} | ||
})); | ||
} | ||
}); | ||
Object.defineProperty(this, "queuedValidationWakeup", { | ||
enumerable: true, | ||
configurable: true, | ||
writable: true, | ||
value: function () { | ||
if (_this.preventNextQueuedValidation) { | ||
_this.preventNextQueuedValidation = false; | ||
return; | ||
} | ||
_this.validate(); | ||
} | ||
}); | ||
/** | ||
* Runs validation with debouncing to keep the UI super smoothly responsive | ||
@@ -389,20 +191,20 @@ * NOTE: | ||
setAutoValidationDefault: mobx_1.action, | ||
getAutoValidationDefault: mobx_1.action, | ||
getAutoValidationDefault: mobx_1.action.bound, | ||
_autoValidationEnabled: mobx_1.observable, | ||
enableAutoValidation: mobx_1.action, | ||
enableAutoValidationAndValidate: mobx_1.action, | ||
disableAutoValidation: mobx_1.action, | ||
enableAutoValidation: mobx_1.action.bound, | ||
enableAutoValidationAndValidate: mobx_1.action.bound, | ||
disableAutoValidation: mobx_1.action.bound, | ||
validators: mobx_1.action, | ||
onUpdate: mobx_1.action, | ||
executeOnUpdate: mobx_1.action, | ||
onDidChange: mobx_1.action, | ||
executeOnDidChange: mobx_1.action, | ||
setAutoValidationDebouncedMs: mobx_1.action, | ||
onUpdate: mobx_1.action.bound, | ||
executeOnUpdate: mobx_1.action.bound, | ||
onDidChange: mobx_1.action.bound, | ||
executeOnDidChange: mobx_1.action.bound, | ||
setAutoValidationDebouncedMs: mobx_1.action.bound, | ||
lastValidationRequest: mobx_1.observable, | ||
preventNextQueuedValidation: mobx_1.observable, | ||
onChange: mobx_1.action, | ||
reset: mobx_1.action, | ||
onChange: mobx_1.action.bound, | ||
reset: mobx_1.action.bound, | ||
validating: mobx_1.observable, | ||
validate: mobx_1.action, | ||
queuedValidationWakeup: mobx_1.action, | ||
validate: mobx_1.action.bound, | ||
queuedValidationWakeup: mobx_1.action.bound, | ||
_setCompositionParent: mobx_1.action | ||
@@ -435,2 +237,129 @@ }); | ||
}); | ||
Object.defineProperty(FieldState.prototype, "getAutoValidationDefault", { | ||
enumerable: false, | ||
configurable: true, | ||
writable: true, | ||
value: function () { | ||
return this._autoValidationDefault; | ||
} | ||
}); | ||
Object.defineProperty(FieldState.prototype, "enableAutoValidation", { | ||
enumerable: false, | ||
configurable: true, | ||
writable: true, | ||
value: function () { | ||
this._autoValidationEnabled = true; | ||
return this; | ||
} | ||
}); | ||
Object.defineProperty(FieldState.prototype, "enableAutoValidationAndValidate", { | ||
enumerable: false, | ||
configurable: true, | ||
writable: true, | ||
value: function () { | ||
this._autoValidationEnabled = true; | ||
return this.validate(); | ||
} | ||
}); | ||
Object.defineProperty(FieldState.prototype, "disableAutoValidation", { | ||
enumerable: false, | ||
configurable: true, | ||
writable: true, | ||
value: function () { | ||
this._autoValidationEnabled = false; | ||
return this; | ||
} | ||
}); | ||
/** | ||
* onUpdate is called whenever we change something in our local state that is significant | ||
* - any validation() call | ||
* - any reset() call | ||
*/ | ||
Object.defineProperty(FieldState.prototype, "onUpdate", { | ||
enumerable: false, | ||
configurable: true, | ||
writable: true, | ||
value: function (handler) { | ||
this._onUpdate = handler; | ||
return this; | ||
} | ||
}); | ||
Object.defineProperty(FieldState.prototype, "executeOnUpdate", { | ||
enumerable: false, | ||
configurable: true, | ||
writable: true, | ||
value: function () { | ||
this._onUpdate && this._onUpdate(this); | ||
} | ||
}); | ||
Object.defineProperty(FieldState.prototype, "onDidChange", { | ||
enumerable: false, | ||
configurable: true, | ||
writable: true, | ||
value: function (handler) { | ||
this._onDidChange = handler; | ||
return this; | ||
} | ||
}); | ||
Object.defineProperty(FieldState.prototype, "executeOnDidChange", { | ||
enumerable: false, | ||
configurable: true, | ||
writable: true, | ||
value: function (config) { | ||
this._onDidChange && this._onDidChange(config); | ||
} | ||
}); | ||
Object.defineProperty(FieldState.prototype, "setAutoValidationDebouncedMs", { | ||
enumerable: false, | ||
configurable: true, | ||
writable: true, | ||
value: function (milliseconds) { | ||
this.queueValidation = mobx_1.action(utils_1.debounce(this.queuedValidationWakeup, milliseconds)); | ||
return this; | ||
} | ||
}); | ||
/** On change on the component side */ | ||
Object.defineProperty(FieldState.prototype, "onChange", { | ||
enumerable: false, | ||
configurable: true, | ||
writable: true, | ||
value: function (value) { | ||
// no long prevent any debounced validation request | ||
this.preventNextQueuedValidation = false; | ||
// Store local old value for onDidChange | ||
var oldValue = this.value; | ||
// Immediately set for local ui binding | ||
this.value = value; | ||
// Call on did change if any | ||
this.executeOnDidChange({ newValue: value, oldValue: oldValue }); | ||
this.dirty = true; | ||
this.executeOnUpdate(); | ||
if (this._autoValidationEnabled) { | ||
this.queueValidation(); | ||
} | ||
} | ||
}); | ||
/** | ||
* If the page wants to reinitialize the field, | ||
* it should call this function | ||
*/ | ||
Object.defineProperty(FieldState.prototype, "reset", { | ||
enumerable: false, | ||
configurable: true, | ||
writable: true, | ||
value: function (value) { | ||
if (value === void 0) { value = this._initValue; } | ||
// If a previous validation comes back ignore it | ||
this.preventNextQueuedValidation = true; | ||
// This value vetos all previous values | ||
this._autoValidationEnabled = this._autoValidationDefault; | ||
this.value = value; | ||
this.error = undefined; | ||
this.dirty = false; | ||
this.hasBeenValidated = false; | ||
this.$ = value; | ||
this._on$Reinit(); | ||
this.executeOnUpdate(); | ||
} | ||
}); | ||
Object.defineProperty(FieldState.prototype, "hasError", { | ||
@@ -443,4 +372,78 @@ get: function () { | ||
}); | ||
/** | ||
* Runs validation on the current value immediately | ||
*/ | ||
Object.defineProperty(FieldState.prototype, "validate", { | ||
enumerable: false, | ||
configurable: true, | ||
writable: true, | ||
value: function () { | ||
var _this = this; | ||
this.lastValidationRequest++; | ||
var lastValidationRequest = this.lastValidationRequest; | ||
this.validating = true; | ||
var value = this.value; | ||
return types_1.applyValidators(this.value, this._validators || []) | ||
.then(mobx_1.action(function (fieldError) { | ||
/** | ||
* If validation comes back out of order then the result of this validation is not siginificant | ||
* We simply copy the value from the last validation attempt | ||
*/ | ||
if (_this.lastValidationRequest !== lastValidationRequest) { | ||
if (_this.hasError) { | ||
return { hasError: true }; | ||
} | ||
else { | ||
return { | ||
hasError: false, | ||
value: _this.$, | ||
}; | ||
} | ||
} | ||
_this.validating = false; | ||
_this.hasBeenValidated = true; | ||
/** For any change in field error, update our error */ | ||
if (fieldError != _this.error) { | ||
_this.error = fieldError; | ||
} | ||
/** Check for error */ | ||
var hasError = _this.hasError; | ||
/** If no error */ | ||
if (!hasError) { | ||
/** Copy over the value to validated value */ | ||
if (_this.$ !== value) { | ||
_this.$ = value; | ||
} | ||
/** Trigger any form level validations if required */ | ||
_this._on$ValidationPass(); | ||
} | ||
/** before returning update */ | ||
_this.executeOnUpdate(); | ||
/** return a result based on error status */ | ||
if (hasError) { | ||
return { hasError: true }; | ||
} | ||
else { | ||
return { | ||
hasError: false, | ||
value: value | ||
}; | ||
} | ||
})); | ||
} | ||
}); | ||
Object.defineProperty(FieldState.prototype, "queuedValidationWakeup", { | ||
enumerable: false, | ||
configurable: true, | ||
writable: true, | ||
value: function () { | ||
if (this.preventNextQueuedValidation) { | ||
this.preventNextQueuedValidation = false; | ||
return; | ||
} | ||
this.validate(); | ||
} | ||
}); | ||
return FieldState; | ||
}()); | ||
exports.FieldState = FieldState; |
@@ -30,3 +30,3 @@ import { ComposibleValidatable, Validator } from './types'; | ||
protected _validators: Validator<TValue>[]; | ||
validators: (...validators: Validator<TValue>[]) => this; | ||
validators(...validators: Validator<TValue>[]): this; | ||
/** | ||
@@ -79,3 +79,3 @@ * - Re-runs validation on all fields | ||
*/ | ||
reset: () => void; | ||
reset(): void; | ||
/** | ||
@@ -85,4 +85,4 @@ * Auto validation | ||
protected autoValidationEnabled: boolean; | ||
enableAutoValidation: () => void; | ||
enableAutoValidationAndValidate: () => Promise<{ | ||
enableAutoValidation(): void; | ||
enableAutoValidationAndValidate(): Promise<{ | ||
hasError: true; | ||
@@ -93,3 +93,3 @@ } | { | ||
}>; | ||
disableAutoValidation: () => void; | ||
disableAutoValidation(): void; | ||
/** | ||
@@ -96,0 +96,0 @@ * Composible field validation tracking |
@@ -94,15 +94,2 @@ "use strict"; | ||
}); | ||
Object.defineProperty(this, "validators", { | ||
enumerable: true, | ||
configurable: true, | ||
writable: true, | ||
value: function () { | ||
var validators = []; | ||
for (var _i = 0; _i < arguments.length; _i++) { | ||
validators[_i] = arguments[_i]; | ||
} | ||
_this._validators = validators; | ||
return _this; | ||
} | ||
}); | ||
Object.defineProperty(this, "_error", { | ||
@@ -115,13 +102,2 @@ enumerable: true, | ||
/** | ||
* Resets all the fields in the form | ||
*/ | ||
Object.defineProperty(this, "reset", { | ||
enumerable: true, | ||
configurable: true, | ||
writable: true, | ||
value: function () { | ||
_this.getValues().map(function (v) { return v.reset(); }); | ||
} | ||
}); | ||
/** | ||
* Auto validation | ||
@@ -135,29 +111,2 @@ */ | ||
}); | ||
Object.defineProperty(this, "enableAutoValidation", { | ||
enumerable: true, | ||
configurable: true, | ||
writable: true, | ||
value: function () { | ||
_this.autoValidationEnabled = true; | ||
_this.getValues().forEach(function (x) { return x.enableAutoValidation(); }); | ||
} | ||
}); | ||
Object.defineProperty(this, "enableAutoValidationAndValidate", { | ||
enumerable: true, | ||
configurable: true, | ||
writable: true, | ||
value: function () { | ||
_this.enableAutoValidation(); | ||
return _this.validate(); | ||
} | ||
}); | ||
Object.defineProperty(this, "disableAutoValidation", { | ||
enumerable: true, | ||
configurable: true, | ||
writable: true, | ||
value: function () { | ||
_this.autoValidationEnabled = false; | ||
_this.getValues().forEach(function (x) { return x.disableAutoValidation(); }); | ||
} | ||
}); | ||
/** | ||
@@ -195,3 +144,3 @@ * Composible field validation tracking | ||
validating: mobx_1.observable, | ||
validators: mobx_1.action, | ||
validators: mobx_1.action.bound, | ||
validate: mobx_1.action, | ||
@@ -207,7 +156,7 @@ _error: mobx_1.observable, | ||
showFormError: mobx_1.computed, | ||
reset: mobx_1.action, | ||
reset: mobx_1.action.bound, | ||
autoValidationEnabled: mobx_1.observable, | ||
enableAutoValidation: mobx_1.action, | ||
enableAutoValidationAndValidate: mobx_1.action, | ||
disableAutoValidation: mobx_1.action, | ||
enableAutoValidation: mobx_1.action.bound, | ||
enableAutoValidationAndValidate: mobx_1.action.bound, | ||
disableAutoValidation: mobx_1.action.bound, | ||
validatedSubFields: mobx_1.observable, | ||
@@ -223,2 +172,15 @@ compose: mobx_1.action, | ||
} | ||
Object.defineProperty(FormState.prototype, "validators", { | ||
enumerable: false, | ||
configurable: true, | ||
writable: true, | ||
value: function () { | ||
var validators = []; | ||
for (var _i = 0; _i < arguments.length; _i++) { | ||
validators[_i] = arguments[_i]; | ||
} | ||
this._validators = validators; | ||
return this; | ||
} | ||
}); | ||
/** | ||
@@ -358,2 +320,40 @@ * - Re-runs validation on all fields | ||
/** | ||
* Resets all the fields in the form | ||
*/ | ||
Object.defineProperty(FormState.prototype, "reset", { | ||
enumerable: false, | ||
configurable: true, | ||
writable: true, | ||
value: function () { | ||
this.getValues().map(function (v) { return v.reset(); }); | ||
} | ||
}); | ||
Object.defineProperty(FormState.prototype, "enableAutoValidation", { | ||
enumerable: false, | ||
configurable: true, | ||
writable: true, | ||
value: function () { | ||
this.autoValidationEnabled = true; | ||
this.getValues().forEach(function (x) { return x.enableAutoValidation(); }); | ||
} | ||
}); | ||
Object.defineProperty(FormState.prototype, "enableAutoValidationAndValidate", { | ||
enumerable: false, | ||
configurable: true, | ||
writable: true, | ||
value: function () { | ||
this.enableAutoValidation(); | ||
return this.validate(); | ||
} | ||
}); | ||
Object.defineProperty(FormState.prototype, "disableAutoValidation", { | ||
enumerable: false, | ||
configurable: true, | ||
writable: true, | ||
value: function () { | ||
this.autoValidationEnabled = false; | ||
this.getValues().forEach(function (x) { return x.disableAutoValidation(); }); | ||
} | ||
}); | ||
/** | ||
* Composible fields (fields that work in conjuction with FormState) | ||
@@ -360,0 +360,0 @@ */ |
@@ -16,3 +16,3 @@ import { Validatable, Validator } from './types'; | ||
protected _validators: Validator<TValue>[]; | ||
validators: (...validators: Validator<TValue>[]) => this; | ||
validators(...validators: Validator<TValue>[]): this; | ||
validate(): Promise<{ | ||
@@ -24,4 +24,4 @@ hasError: true; | ||
}>; | ||
enableAutoValidation: () => void; | ||
disableAutoValidation: () => void; | ||
enableAutoValidation(): void; | ||
disableAutoValidation(): void; | ||
protected _error: string | null | undefined; | ||
@@ -28,0 +28,0 @@ /** |
@@ -49,3 +49,2 @@ "use strict"; | ||
getFields) { | ||
var _this = this; | ||
Object.defineProperty(this, "getFields", { | ||
@@ -69,31 +68,2 @@ enumerable: true, | ||
}); | ||
Object.defineProperty(this, "validators", { | ||
enumerable: true, | ||
configurable: true, | ||
writable: true, | ||
value: function () { | ||
var validators = []; | ||
for (var _i = 0; _i < arguments.length; _i++) { | ||
validators[_i] = arguments[_i]; | ||
} | ||
_this._validators = validators; | ||
return _this; | ||
} | ||
}); | ||
Object.defineProperty(this, "enableAutoValidation", { | ||
enumerable: true, | ||
configurable: true, | ||
writable: true, | ||
value: function () { | ||
_this.getFields().forEach(function (x) { return x.enableAutoValidation(); }); | ||
} | ||
}); | ||
Object.defineProperty(this, "disableAutoValidation", { | ||
enumerable: true, | ||
configurable: true, | ||
writable: true, | ||
value: function () { | ||
_this.getFields().forEach(function (x) { return x.disableAutoValidation(); }); | ||
} | ||
}); | ||
Object.defineProperty(this, "_error", { | ||
@@ -108,6 +78,6 @@ enumerable: true, | ||
validating: mobx_1.observable, | ||
validators: mobx_1.action, | ||
validators: mobx_1.action.bound, | ||
validate: mobx_1.action, | ||
enableAutoValidation: mobx_1.action, | ||
disableAutoValidation: mobx_1.action, | ||
enableAutoValidation: mobx_1.action.bound, | ||
disableAutoValidation: mobx_1.action.bound, | ||
_error: mobx_1.observable, | ||
@@ -131,2 +101,15 @@ hasError: mobx_1.computed, | ||
}); | ||
Object.defineProperty(FormStateLazy.prototype, "validators", { | ||
enumerable: false, | ||
configurable: true, | ||
writable: true, | ||
value: function () { | ||
var validators = []; | ||
for (var _i = 0; _i < arguments.length; _i++) { | ||
validators[_i] = arguments[_i]; | ||
} | ||
this._validators = validators; | ||
return this; | ||
} | ||
}); | ||
Object.defineProperty(FormStateLazy.prototype, "validate", { | ||
@@ -177,2 +160,18 @@ enumerable: false, | ||
}); | ||
Object.defineProperty(FormStateLazy.prototype, "enableAutoValidation", { | ||
enumerable: false, | ||
configurable: true, | ||
writable: true, | ||
value: function () { | ||
this.getFields().forEach(function (x) { return x.enableAutoValidation(); }); | ||
} | ||
}); | ||
Object.defineProperty(FormStateLazy.prototype, "disableAutoValidation", { | ||
enumerable: false, | ||
configurable: true, | ||
writable: true, | ||
value: function () { | ||
this.getFields().forEach(function (x) { return x.disableAutoValidation(); }); | ||
} | ||
}); | ||
Object.defineProperty(FormStateLazy.prototype, "hasError", { | ||
@@ -179,0 +178,0 @@ /** |
{ | ||
"name": "formstate", | ||
"version": "2.0.0", | ||
"version": "2.1.0", | ||
"description": "Painless and simple MobX form management", | ||
@@ -38,8 +38,8 @@ "main": "./lib/index.js", | ||
"devDependencies": { | ||
"@material-ui/core": "4.9.3", | ||
"@material-ui/core": "4.12.4", | ||
"@types/fs-extra": "8.0.0", | ||
"@types/mocha": "5.2.6", | ||
"@types/node": "12.7.4", | ||
"@types/react": "16.9.2", | ||
"@types/react-dom": "16.9.0", | ||
"@types/react": "18.0.15", | ||
"@types/react-dom": "18.0.6", | ||
"concurrently": "4.1.2", | ||
@@ -55,4 +55,4 @@ "csstips": "1.1.0", | ||
"moment": "2.24.0", | ||
"react": "16.9.0", | ||
"react-dom": "16.9.0", | ||
"react": "18.2.0", | ||
"react-dom": "18.2.0", | ||
"starts": "0.8.0", | ||
@@ -59,0 +59,0 @@ "ts-node": "8.3.0", |
@@ -52,14 +52,16 @@ import { observable, action, runInAction, makeObservable } from 'mobx'; | ||
} | ||
public getAutoValidationDefault = () => this._autoValidationDefault; | ||
public getAutoValidationDefault() { | ||
return this._autoValidationDefault; | ||
} | ||
protected _autoValidationEnabled = this._autoValidationDefault; | ||
public enableAutoValidation = () => { | ||
public enableAutoValidation() { | ||
this._autoValidationEnabled = true; | ||
return this; | ||
} | ||
public enableAutoValidationAndValidate = () => { | ||
public enableAutoValidationAndValidate() { | ||
this._autoValidationEnabled = true; | ||
return this.validate(); | ||
} | ||
public disableAutoValidation = () => { | ||
public disableAutoValidation() { | ||
this._autoValidationEnabled = false; | ||
@@ -79,20 +81,20 @@ return this; | ||
setAutoValidationDefault: action, | ||
getAutoValidationDefault: action, | ||
getAutoValidationDefault: action.bound, | ||
_autoValidationEnabled: observable, | ||
enableAutoValidation: action, | ||
enableAutoValidationAndValidate: action, | ||
disableAutoValidation: action, | ||
enableAutoValidation: action.bound, | ||
enableAutoValidationAndValidate: action.bound, | ||
disableAutoValidation: action.bound, | ||
validators: action, | ||
onUpdate: action, | ||
executeOnUpdate: action, | ||
onDidChange: action, | ||
executeOnDidChange: action, | ||
setAutoValidationDebouncedMs: action, | ||
onUpdate: action.bound, | ||
executeOnUpdate: action.bound, | ||
onDidChange: action.bound, | ||
executeOnDidChange: action.bound, | ||
setAutoValidationDebouncedMs: action.bound, | ||
lastValidationRequest: observable, | ||
preventNextQueuedValidation: observable, | ||
onChange: action, | ||
reset: action, | ||
onChange: action.bound, | ||
reset: action.bound, | ||
validating: observable, | ||
validate: action, | ||
queuedValidationWakeup: action, | ||
validate: action.bound, | ||
queuedValidationWakeup: action.bound, | ||
_setCompositionParent: action | ||
@@ -123,7 +125,7 @@ }); | ||
*/ | ||
public onUpdate = (handler: (state: FieldState<TValue>) => any) => { | ||
public onUpdate(handler: (state: FieldState<TValue>) => any) { | ||
this._onUpdate = handler; | ||
return this; | ||
} | ||
protected executeOnUpdate = () => { | ||
protected executeOnUpdate() { | ||
this._onUpdate && this._onUpdate(this); | ||
@@ -136,11 +138,11 @@ } | ||
protected _onDidChange: (config: { newValue: TValue, oldValue: TValue }) => any; | ||
public onDidChange = (handler: (config: { newValue: TValue, oldValue: TValue }) => any) => { | ||
public onDidChange(handler: (config: { newValue: TValue, oldValue: TValue }) => any) { | ||
this._onDidChange = handler; | ||
return this; | ||
} | ||
protected executeOnDidChange = (config: { newValue: TValue, oldValue: TValue }) => { | ||
protected executeOnDidChange(config: { newValue: TValue, oldValue: TValue }) { | ||
this._onDidChange && this._onDidChange(config); | ||
} | ||
public setAutoValidationDebouncedMs = (milliseconds: number) => { | ||
public setAutoValidationDebouncedMs(milliseconds: number) { | ||
this.queueValidation = action(debounce(this.queuedValidationWakeup, milliseconds)); | ||
@@ -155,3 +157,3 @@ return this; | ||
/** On change on the component side */ | ||
onChange = (value: TValue) => { | ||
onChange(value: TValue) { | ||
// no long prevent any debounced validation request | ||
@@ -179,3 +181,3 @@ this.preventNextQueuedValidation = false; | ||
*/ | ||
reset = (value: TValue = this._initValue) => { | ||
reset(value: TValue = this._initValue) { | ||
// If a previous validation comes back ignore it | ||
@@ -204,3 +206,3 @@ this.preventNextQueuedValidation = true; | ||
*/ | ||
validate = (): Promise<{ hasError: true } | { hasError: false, value: TValue }> => { | ||
validate(): Promise<{ hasError: true } | { hasError: false, value: TValue }> { | ||
this.lastValidationRequest++; | ||
@@ -266,3 +268,3 @@ const lastValidationRequest = this.lastValidationRequest; | ||
queuedValidationWakeup = () => { | ||
queuedValidationWakeup() { | ||
if (this.preventNextQueuedValidation) { | ||
@@ -269,0 +271,0 @@ this.preventNextQueuedValidation = false; |
@@ -31,3 +31,3 @@ import { action, computed, isObservable, isObservableArray, IObservableArray, observable, runInAction, makeObservable } from 'mobx'; | ||
validating: observable, | ||
validators: action, | ||
validators: action.bound, | ||
validate: action, | ||
@@ -43,7 +43,7 @@ _error: observable, | ||
showFormError: computed, | ||
reset: action, | ||
reset: action.bound, | ||
autoValidationEnabled: observable, | ||
enableAutoValidation: action, | ||
enableAutoValidationAndValidate: action, | ||
disableAutoValidation: action, | ||
enableAutoValidation: action.bound, | ||
enableAutoValidationAndValidate: action.bound, | ||
disableAutoValidation: action.bound, | ||
validatedSubFields: observable, | ||
@@ -75,3 +75,3 @@ compose: action, | ||
protected _validators: Validator<TValue>[] = []; | ||
validators = (...validators: Validator<TValue>[]) => { | ||
validators(...validators: Validator<TValue>[]) { | ||
this._validators = validators; | ||
@@ -181,3 +181,3 @@ return this; | ||
*/ | ||
reset = () => { | ||
reset() { | ||
this.getValues().map(v => v.reset()); | ||
@@ -190,11 +190,11 @@ } | ||
protected autoValidationEnabled = false; | ||
public enableAutoValidation = () => { | ||
public enableAutoValidation() { | ||
this.autoValidationEnabled = true; | ||
this.getValues().forEach(x => x.enableAutoValidation()); | ||
} | ||
public enableAutoValidationAndValidate = () => { | ||
public enableAutoValidationAndValidate() { | ||
this.enableAutoValidation(); | ||
return this.validate(); | ||
} | ||
public disableAutoValidation = () => { | ||
public disableAutoValidation() { | ||
this.autoValidationEnabled = false; | ||
@@ -201,0 +201,0 @@ this.getValues().forEach(x => x.disableAutoValidation()); |
@@ -21,6 +21,6 @@ import { observable, action, computed, runInAction, makeObservable } from 'mobx'; | ||
validating: observable, | ||
validators: action, | ||
validators: action.bound, | ||
validate: action, | ||
enableAutoValidation: action, | ||
disableAutoValidation: action, | ||
enableAutoValidation: action.bound, | ||
disableAutoValidation: action.bound, | ||
_error: observable, | ||
@@ -41,3 +41,3 @@ hasError: computed, | ||
protected _validators: Validator<TValue>[] = []; | ||
validators = (...validators: Validator<TValue>[]) => { | ||
validators (...validators: Validator<TValue>[]) { | ||
this._validators = validators; | ||
@@ -78,6 +78,6 @@ return this; | ||
enableAutoValidation = () => { | ||
enableAutoValidation() { | ||
this.getFields().forEach(x => x.enableAutoValidation()); | ||
} | ||
disableAutoValidation = () => { | ||
disableAutoValidation() { | ||
this.getFields().forEach(x => x.disableAutoValidation()); | ||
@@ -84,0 +84,0 @@ } |
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
2284
87040