Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

formstate

Package Overview
Dependencies
Maintainers
2
Versions
38
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

formstate - npm Package Compare versions

Comparing version 0.6.0 to 0.7.0

19

lib/index.d.ts

@@ -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;

2

package.json
{
"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;
}
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc