@shopify/react-form-state
Advanced tools
Comparing version 0.10.0 to 0.10.1
@@ -50,5 +50,3 @@ "use strict"; | ||
var key = getChildKey ? getChildKey(fieldValues) : index; | ||
return ( | ||
// eslint-disable-next-line | ||
React.createElement(React.Fragment, { key: key }, children(innerFields, index))); | ||
return (React.createElement(React.Fragment, { key: key }, children(innerFields, index))); | ||
}); | ||
@@ -55,0 +53,0 @@ }; |
@@ -44,3 +44,3 @@ import * as React from 'react'; | ||
} | ||
export default class FormState<Fields extends Object> extends React.PureComponent<Props<Fields>, State<Fields>> { | ||
export default class FormState<Fields extends object> extends React.PureComponent<Props<Fields>, State<Fields>> { | ||
static List: typeof List; | ||
@@ -47,0 +47,0 @@ static Nested: typeof Nested; |
@@ -15,2 +15,3 @@ "use strict"; | ||
_this.fieldsWithHandlers = new WeakMap(); | ||
// eslint-disable-next-line shopify/react-prefer-private-members | ||
_this.reset = function () { | ||
@@ -69,3 +70,2 @@ return new Promise(function (resolve) { | ||
if (_this.fieldsWithHandlers.has(field)) { | ||
// eslint-disable-next-line typescript/no-non-null-assertion | ||
return _this.fieldsWithHandlers.get(field); | ||
@@ -117,2 +117,3 @@ } | ||
}; | ||
// eslint-disable-next-line shopify/react-prefer-private-members | ||
FormState.prototype.validateForm = function () { | ||
@@ -193,5 +194,3 @@ var _this = this; | ||
var field = fields[fieldPath]; | ||
var newValue = typeof value === 'function' | ||
? value(field.value) | ||
: value; | ||
var newValue = typeof value === 'function' ? value(field.value) : value; | ||
var dirty = !utilities_1.isEqual(newValue, field.initialValue); | ||
@@ -266,3 +265,2 @@ var updatedField = _this.getUpdatedField({ | ||
var fields = this.state.fields; | ||
// eslint-disable-next-line consistent-return | ||
return runValidator(validators[fieldPath], value, fields); | ||
@@ -343,7 +341,5 @@ }; | ||
if (typeof validate === 'function') { | ||
// eslint-disable-next-line consistent-return | ||
return validate(value, fields); | ||
} | ||
if (!Array.isArray(validate)) { | ||
// eslint-disable-next-line consistent-return | ||
return; | ||
@@ -355,6 +351,4 @@ } | ||
if (errors.length === 0) { | ||
// eslint-disable-next-line consistent-return | ||
return; | ||
} | ||
// eslint-disable-next-line consistent-return | ||
return errors; | ||
@@ -371,2 +365,3 @@ } | ||
}); | ||
// eslint-disable-next-line @typescript-eslint/no-object-literal-type-assertion | ||
return tslib_1.__assign({}, state, { fields: updatedFields }); | ||
@@ -373,0 +368,0 @@ } |
@@ -5,3 +5,2 @@ "use strict"; | ||
var React = tslib_1.__importStar(require("react")); | ||
// eslint-disable-next-line react/prefer-stateless-function | ||
var Input = /** @class */ (function (_super) { | ||
@@ -14,8 +13,10 @@ tslib_1.__extends(Input, _super); | ||
var _a = this.props, onChange = _a.onChange, onRender = _a.onRender, inputProps = tslib_1.__rest(_a, ["onChange", "onRender"]); | ||
onRender && onRender(); | ||
return (React.createElement("input", tslib_1.__assign({ | ||
// eslint-disable-next-line react/jsx-no-bind | ||
onChange: function (_a) { | ||
if (onRender) { | ||
onRender(); | ||
} | ||
return (React.createElement("input", tslib_1.__assign({ onChange: function (_a) { | ||
var currentTarget = _a.currentTarget; | ||
onChange && onChange(currentTarget.value); | ||
if (onChange) { | ||
onChange(currentTarget.value); | ||
} | ||
} }, inputProps))); | ||
@@ -22,0 +23,0 @@ }; |
@@ -5,3 +5,2 @@ "use strict"; | ||
var React = tslib_1.__importStar(require("react")); | ||
// eslint-disable-next-line react/prefer-stateless-function | ||
var Input = /** @class */ (function (_super) { | ||
@@ -14,4 +13,6 @@ tslib_1.__extends(Input, _super); | ||
var _a = this.props, onRender = _a.onRender, field = _a.field; | ||
onRender && onRender(); | ||
return (React.createElement("input", tslib_1.__assign({}, field))); | ||
if (onRender) { | ||
onRender(); | ||
} | ||
return React.createElement("input", tslib_1.__assign({}, field)); | ||
}; | ||
@@ -18,0 +19,0 @@ return Input; |
@@ -7,3 +7,3 @@ import isEqual from 'fast-deep-equal'; | ||
export declare function replace<T>(array: T[], targetIndex: number, newValue: T): T[]; | ||
export declare function set<InputType extends Object>(rootObject: InputType, path: string[], value: any): any; | ||
export declare function set<InputType extends object>(rootObject: InputType, path: string[], value: any): any; | ||
export declare function flatMap<T>(array: any[], mapper: (item: any, index?: number) => T | T[]): T[]; |
@@ -45,2 +45,3 @@ "use strict"; | ||
var _c = tslib_1.__read(path), current = _c[0], rest = _c.slice(1); | ||
// eslint-disable-next-line @typescript-eslint/no-object-literal-type-assertion | ||
return tslib_1.__assign({}, rootObject, (_b = {}, _b[current] = set(rootObject[current] || {}, rest, value), _b)); | ||
@@ -47,0 +48,0 @@ } |
@@ -18,5 +18,5 @@ interface Matcher<Input, Fields> { | ||
export declare function isEmptyString(input: string): boolean; | ||
export declare function not<A extends Array<any>, R>(fn: (...a: A) => R): (...args: A) => boolean; | ||
export declare function validateNested<Input extends Object, Fields>(validatorDictionary: any): (input: Input, fields: Fields) => any; | ||
export declare function validateList<Input extends Object, Fields>(validatorDictionary: any): (input: Input[], fields: Fields) => any[] | undefined; | ||
export declare function not<A extends any[], R>(fn: (...xs: A) => R): (...args: A) => boolean; | ||
export declare function validateNested<Input extends object, Fields>(validatorDictionary: any): (input: Input, fields: Fields) => any; | ||
export declare function validateList<Input extends object, Fields>(validatorDictionary: any): (input: Input[], fields: Fields) => any[] | undefined; | ||
export declare function validate<Input>(matcher: Matcher<Input, any>, errorContent: ErrorContent): (input: Input) => ErrorContent | undefined | void; | ||
@@ -23,0 +23,0 @@ export declare function validateRequired<Input>(matcher: Matcher<Input, any>, errorContent: ErrorContent): (input: Input) => ErrorContent | undefined | void; |
@@ -22,3 +22,2 @@ "use strict"; | ||
function isEmpty(input) { | ||
// eslint-disable-next-line no-undefined | ||
return input === null || input === undefined || input.length === 0; | ||
@@ -42,3 +41,2 @@ } | ||
function validateNested(validatorDictionary) { | ||
// eslint-disable-next-line consistent-return | ||
return function (input, fields) { | ||
@@ -54,3 +52,2 @@ var errors = utilities_1.mapObject(input, function (value, field) { | ||
if (!Array.isArray(validate)) { | ||
// eslint-disable-next-line consistent-return | ||
return; | ||
@@ -62,3 +59,2 @@ } | ||
if (errors.length === 0) { | ||
// eslint-disable-next-line consistent-return | ||
return; | ||
@@ -79,3 +75,2 @@ } | ||
var validateItem = validateNested(validatorDictionary); | ||
// eslint-disable-next-line consistent-return | ||
return function (input, fields) { | ||
@@ -103,6 +98,4 @@ var errors = input.map(function (item) { return validateItem(item, fields); }); | ||
if (typeof errorContent === 'function') { | ||
// eslint-disable-next-line consistent-return | ||
return errorContent(toString(input)); | ||
} | ||
// eslint-disable-next-line consistent-return | ||
return errorContent; | ||
@@ -119,6 +112,4 @@ }; | ||
if (typeof errorContent === 'function') { | ||
// eslint-disable-next-line consistent-return | ||
return errorContent(toString(input)); | ||
} | ||
// eslint-disable-next-line consistent-return | ||
return errorContent; | ||
@@ -125,0 +116,0 @@ }; |
{ | ||
"name": "@shopify/react-form-state", | ||
"version": "0.10.0", | ||
"version": "0.10.1", | ||
"license": "MIT", | ||
@@ -33,3 +33,3 @@ "description": "Manage react forms tersely and type-safe with no magic.", | ||
"devDependencies": { | ||
"@shopify/enzyme-utilities": "^2.0.0", | ||
"@shopify/enzyme-utilities": "^2.0.1", | ||
"@types/enzyme": "^3.1.10", | ||
@@ -36,0 +36,0 @@ "faker": "^4.1.0", |
@@ -66,3 +66,3 @@ /* eslint-disable no-case-declarations */ | ||
export default class FormState< | ||
Fields extends Object | ||
Fields extends object | ||
> extends React.PureComponent<Props<Fields>, State<Fields>> { | ||
@@ -112,3 +112,7 @@ static List = List; | ||
state = createFormState(this.props.initialValues, this.props.externalErrors); | ||
state: State<Fields> = createFormState( | ||
this.props.initialValues, | ||
this.props.externalErrors, | ||
); | ||
private mounted = false; | ||
@@ -138,2 +142,3 @@ private fieldsWithHandlers = new WeakMap(); | ||
// eslint-disable-next-line shopify/react-prefer-private-members | ||
public validateForm() { | ||
@@ -145,2 +150,3 @@ return new Promise(resolve => { | ||
// eslint-disable-next-line shopify/react-prefer-private-members | ||
public reset = () => { | ||
@@ -256,4 +262,3 @@ return new Promise(resolve => { | ||
if (this.fieldsWithHandlers.has(field)) { | ||
// eslint-disable-next-line typescript/no-non-null-assertion | ||
return this.fieldsWithHandlers.get(field)!; | ||
return this.fieldsWithHandlers.get(field); | ||
} | ||
@@ -278,6 +283,3 @@ | ||
const newValue = | ||
typeof value === 'function' | ||
? (value as ValueMapper<Fields[Key]>)(field.value) | ||
: value; | ||
const newValue = typeof value === 'function' ? value(field.value) : value; | ||
@@ -399,3 +401,2 @@ const dirty = !isEqual(newValue, field.initialValue); | ||
// eslint-disable-next-line consistent-return | ||
return runValidator(validators[fieldPath], value, fields); | ||
@@ -501,3 +502,2 @@ } | ||
if (typeof validate === 'function') { | ||
// eslint-disable-next-line consistent-return | ||
return validate(value, fields); | ||
@@ -507,3 +507,2 @@ } | ||
if (!Array.isArray(validate)) { | ||
// eslint-disable-next-line consistent-return | ||
return; | ||
@@ -517,7 +516,5 @@ } | ||
if (errors.length === 0) { | ||
// eslint-disable-next-line consistent-return | ||
return; | ||
} | ||
// eslint-disable-next-line consistent-return | ||
return errors; | ||
@@ -544,2 +541,3 @@ } | ||
// eslint-disable-next-line @typescript-eslint/no-object-literal-type-assertion | ||
return { | ||
@@ -546,0 +544,0 @@ ...state, |
@@ -33,3 +33,3 @@ import isEqual from 'fast-deep-equal'; | ||
export function set<InputType extends Object>( | ||
export function set<InputType extends object>( | ||
rootObject: InputType, | ||
@@ -48,2 +48,4 @@ path: string[], | ||
const [current, ...rest] = path; | ||
// eslint-disable-next-line @typescript-eslint/no-object-literal-type-assertion | ||
return { | ||
@@ -50,0 +52,0 @@ ...(rootObject as any), |
@@ -30,3 +30,2 @@ import {mapObject} from './utilities'; | ||
export function isEmpty(input: any) { | ||
// eslint-disable-next-line no-undefined | ||
return input === null || input === undefined || input.length === 0; | ||
@@ -39,10 +38,9 @@ } | ||
export function not<A extends Array<any>, R>(fn: (...a: A) => R) { | ||
export function not<A extends any[], R>(fn: (...xs: A) => R) { | ||
return (...args: A) => !fn(...args); | ||
} | ||
export function validateNested<Input extends Object, Fields>( | ||
export function validateNested<Input extends object, Fields>( | ||
validatorDictionary: any, | ||
) { | ||
// eslint-disable-next-line consistent-return | ||
return (input: Input, fields: Fields) => { | ||
@@ -61,3 +59,2 @@ const errors = mapObject<Input, any>(input, (value, field) => { | ||
if (!Array.isArray(validate)) { | ||
// eslint-disable-next-line consistent-return | ||
return; | ||
@@ -71,3 +68,2 @@ } | ||
if (errors.length === 0) { | ||
// eslint-disable-next-line consistent-return | ||
return; | ||
@@ -88,7 +84,7 @@ } | ||
export function validateList<Input extends Object, Fields>( | ||
export function validateList<Input extends object, Fields>( | ||
validatorDictionary: any, | ||
) { | ||
const validateItem = validateNested(validatorDictionary); | ||
// eslint-disable-next-line consistent-return | ||
return (input: Input[], fields: Fields) => { | ||
@@ -128,7 +124,5 @@ const errors = input.map(item => validateItem(item, fields)); | ||
if (typeof errorContent === 'function') { | ||
// eslint-disable-next-line consistent-return | ||
return errorContent(toString(input)); | ||
} | ||
// eslint-disable-next-line consistent-return | ||
return errorContent; | ||
@@ -155,7 +149,5 @@ }; | ||
if (typeof errorContent === 'function') { | ||
// eslint-disable-next-line consistent-return | ||
return errorContent(toString(input)); | ||
} | ||
// eslint-disable-next-line consistent-return | ||
return errorContent; | ||
@@ -162,0 +154,0 @@ }; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
191056
4199