formula-one
Advanced tools
Comparing version 0.9.6 to 0.9.7
# Changelog | ||
### v0.9.7 | ||
- Update Flow and other dev dependencies | ||
- Fully annotate expressions to enable [local type inference](https://medium.com/flow-type/local-type-inference-for-flow-aaa65d071347) | ||
### v0.9.6 | ||
@@ -4,0 +9,0 @@ |
@@ -215,3 +215,3 @@ "use strict"; | ||
var _newChild = updateAtPath(restStep, updater, nextTree); // $FlowFixMe[incompatible-return](zach): I think this is safe, might need GADTs for the type checker to understand why | ||
var _newChild = updateAtPath(restStep, updater, nextTree); // $FlowFixMe[incompatible-call](zach): I think this is safe, might need GADTs for the type checker to understand why | ||
@@ -218,0 +218,0 @@ |
{ | ||
"name": "formula-one", | ||
"version": "0.9.6", | ||
"version": "0.9.7", | ||
"description": "Strongly-typed React form state management", | ||
@@ -48,3 +48,3 @@ "author": "Zach Gotsch", | ||
"babel-eslint": "^10", | ||
"babel-jest": "^24", | ||
"babel-jest": "^27", | ||
"eslint": "5.x", | ||
@@ -58,4 +58,4 @@ "eslint-config-react-app": "^3.0.4", | ||
"flow-typed": "^2.6.1", | ||
"jest": "^24.5.0", | ||
"prettier": "^1.18.2", | ||
"jest": "^27.4.7", | ||
"prettier": "^2.5.1", | ||
"react": "^17.0.1", | ||
@@ -62,0 +62,0 @@ "react-test-renderer": "^17.0.1" |
@@ -5,3 +5,3 @@ # formula-one | ||
[![CircleCI](https://circleci.com/gh/flexport/formula-one.svg?style=svg)](https://circleci.com/gh/flexport/formula-one) | ||
[![Yarn Test](https://github.com/flexport/formula-one/actions/workflows/test.yml/badge.svg)](https://github.com/flexport/formula-one/actions/workflows/test.yml) | ||
@@ -215,3 +215,3 @@ ## A minimal example, with no validation | ||
export default function() { | ||
export default function () { | ||
return ( | ||
@@ -218,0 +218,0 @@ <div className="App"> |
@@ -228,8 +228,7 @@ // @flow strict | ||
const newNodeSpans: Array< | ||
[number, $ReadOnlyArray<ShapedTree<E, Extras>>] | ||
> = spans.map(([index, content]) => [ | ||
index, | ||
content.map(v => treeFromValue(v, cleanNode)), | ||
]); | ||
const newNodeSpans: Array<[number, $ReadOnlyArray<ShapedTree<E, Extras>>]> = | ||
spans.map(([index, content]) => [ | ||
index, | ||
content.map(v => treeFromValue(v, cleanNode)), | ||
]); | ||
const newTree = dangerouslySetChildren( | ||
@@ -251,3 +250,7 @@ insertSpans(newNodeSpans, shapedArrayChildren(oldTree)), | ||
zipped.filter(([value], i, arr) => | ||
predicate(value, i, arr.map(([v]) => v)) | ||
predicate( | ||
value, | ||
i, | ||
arr.map(([v]) => v) | ||
) | ||
) | ||
@@ -295,3 +298,12 @@ ); | ||
filterPredicate !== undefined | ||
? ([v, _], i, arr) => filterPredicate(v, i, arr.map(([v, _]) => v)) | ||
? ( | ||
[v, _]: [E, ShapedTree<E, Extras>], | ||
i: number, | ||
arr: $ReadOnlyArray<[E, ShapedTree<E, Extras>]> | ||
) => | ||
filterPredicate( | ||
v, | ||
i, | ||
arr.map(([v, _]) => v) | ||
) | ||
: undefined; | ||
@@ -298,0 +310,0 @@ |
@@ -9,3 +9,3 @@ // @flow strict | ||
function flattenErrors(errors: Err) { | ||
let flatErrors = []; | ||
let flatErrors: string[] = []; | ||
if (errors.client !== "pending") { | ||
@@ -12,0 +12,0 @@ flatErrors = flatErrors.concat(errors.client); |
@@ -28,4 +28,6 @@ // @flow strict | ||
export type FieldProps<T> = Props<T>; | ||
function getErrors(errors: Err) { | ||
let flatErrors = []; | ||
let flatErrors: string[] = []; | ||
if (errors.client !== "pending") { | ||
@@ -32,0 +34,0 @@ flatErrors = flatErrors.concat(errors.client); |
@@ -79,12 +79,11 @@ // @flow strict | ||
|}; | ||
export const FormContext: React.Context< | ||
FormContextPayload<mixed> | ||
> = React.createContext({ | ||
shouldShowError: () => true, | ||
pristine: false, | ||
submitted: true, | ||
registerValidation: () => ({replace: () => {}, unregister: () => {}}), | ||
applyCustomChangeToTree: (path, formState) => formState, | ||
applyChangeToNode: (path, formState) => formState, | ||
}); | ||
export const FormContext: React.Context<FormContextPayload<mixed>> = | ||
React.createContext({ | ||
shouldShowError: () => true, | ||
pristine: false, | ||
submitted: true, | ||
registerValidation: () => ({replace: () => {}, unregister: () => {}}), | ||
applyCustomChangeToTree: (path, formState) => formState, | ||
applyChangeToNode: (path, formState) => formState, | ||
}); | ||
@@ -153,3 +152,3 @@ function applyExternalErrorsToFormState<T>( | ||
function getValueAtPath(path: Path, value: Value) { | ||
function getValueAtPath(path: Path, value: Value): Value { | ||
if (path.length === 0) { | ||
@@ -218,3 +217,4 @@ return value; | ||
const errors = paths.reduce( | ||
(errors, validationFn) => errors.concat(validationFn(valueAtPath)), | ||
(errors: Array<string>, validationFn: Validation<mixed>) => | ||
errors.concat(validationFn(valueAtPath)), | ||
[] | ||
@@ -221,0 +221,0 @@ ); |
@@ -54,3 +54,3 @@ // @flow strict | ||
let flatErrors = []; | ||
let flatErrors: string[] = []; | ||
if (errors.client !== "pending") { | ||
@@ -57,0 +57,0 @@ flatErrors = flatErrors.concat(errors.client); |
@@ -57,7 +57,7 @@ // @flow strict | ||
const l = { | ||
formState: objectChild(k, formState), | ||
onChange: childFormState => { | ||
formState: objectChild<_, mixed>(k, formState), | ||
onChange: (childFormState: FormState<V>) => { | ||
onChildChange(k, childFormState); | ||
}, | ||
onBlur: childTree => { | ||
onBlur: (childTree: ShapedTree<V, Extras>) => { | ||
onChildBlur(k, childTree); | ||
@@ -163,3 +163,3 @@ }, | ||
const links = makeLinks( | ||
const links = makeLinks<_, mixed>( | ||
this.props.link.path, | ||
@@ -166,0 +166,0 @@ this.props.link.formState, |
@@ -15,3 +15,3 @@ // @flow strict | ||
export /* opaque */ type ShapedPath<Shape> = Path; | ||
export const rootPath: <T>() => ShapedPath<T> = () => []; | ||
export const rootPath = <T>(): ShapedPath<T> => ([]: ShapedPath<T>); | ||
@@ -172,3 +172,3 @@ // Take shape from value, data from nodeData | ||
); | ||
const newChild = updateAtPath( | ||
const newChild = updateAtPath<mixed, _>( | ||
restStep, | ||
@@ -191,4 +191,4 @@ updater, | ||
); | ||
const newChild = updateAtPath(restStep, updater, nextTree); | ||
// $FlowFixMe[incompatible-return](zach): I think this is safe, might need GADTs for the type checker to understand why | ||
const newChild = updateAtPath<mixed, _>(restStep, updater, nextTree); | ||
// $FlowFixMe[incompatible-call](zach): I think this is safe, might need GADTs for the type checker to understand why | ||
return dangerouslyReplaceObjectChild(firstStep.key, newChild, tree); | ||
@@ -195,0 +195,0 @@ } |
@@ -22,5 +22,3 @@ // @flow strict | ||
export function leaf<T>( | ||
data: T | ||
): {| | ||
export function leaf<T>(data: T): {| | ||
type: "leaf", | ||
@@ -104,3 +102,3 @@ data: T, | ||
...memo, | ||
[k]: strictZipWith(f, left.children[k], right.children[k]), | ||
[(k: string)]: strictZipWith(f, left.children[k], right.children[k]), | ||
}; | ||
@@ -143,3 +141,6 @@ }, ({}: {[string]: Tree<C>})), | ||
children: Object.keys(tree.children).reduce( | ||
(memo, key) => ({...memo, [key]: mapTree(f, tree.children[key])}), | ||
(memo, key) => ({ | ||
...memo, | ||
[(key: string)]: mapTree(f, tree.children[key]), | ||
}), | ||
({}: {[string]: Tree<B>}) | ||
@@ -146,0 +147,0 @@ ), |
@@ -44,3 +44,3 @@ // @flow strict | ||
): Array<E> { | ||
let sortedSpans = []; | ||
let sortedSpans: Array<AddSpan<E>> = []; | ||
if (insertSpans !== undefined) { | ||
@@ -120,3 +120,3 @@ // no duplicated indices are allowed, ECMAScript Array.sort is not stable by spec | ||
): [Array<A>, Array<B>] { | ||
const ret = [[], []]; | ||
const ret: [A[], B[]] = [[], []]; | ||
for (let i = 0; i < zipped.length; i += 1) { | ||
@@ -123,0 +123,0 @@ const [left, right] = zipped[i]; |
@@ -16,3 +16,3 @@ // @flow strict | ||
return Object.keys(left).reduce((memo, k) => { | ||
return Object.keys(left).reduce<$ObjMap<O, <X>(X) => C>>((memo, k) => { | ||
memo[k] = f(left[k], right[k]); | ||
@@ -19,0 +19,0 @@ return memo; |
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
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
501653
68
11300
0