Skip to content

Commit 57a228f

Browse files
authored
Fix exported flow types (#185)
* Fix exported flow types * FF v4.3.0
1 parent 6d5221e commit 57a228f

File tree

8 files changed

+853
-110
lines changed

8 files changed

+853
-110
lines changed

package-lock.json

Lines changed: 768 additions & 48 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package-scripts.js

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,15 @@ module.exports = {
5151
},
5252
andTest: series.nps('build', 'test.size')
5353
},
54-
copyTypes: npsUtils.copy('src/*.js.flow src/*.d.ts dist'),
54+
copyTypes: series(
55+
npsUtils.copy('src/*.js.flow src/*.d.ts dist'),
56+
npsUtils.copy(
57+
'dist/index.js.flow dist --rename="react-final-form.cjs.js.flow"'
58+
),
59+
npsUtils.copy(
60+
'dist/index.js.flow dist --rename="react-final-form.es.js.flow"'
61+
)
62+
),
5563
docs: {
5664
description: 'Generates table of contents in README',
5765
script: 'doctoc README.md'
@@ -71,7 +79,13 @@ module.exports = {
7179
validate: {
7280
description:
7381
'This runs several scripts to make sure things look good before committing or on clean install',
74-
default: concurrent.nps('lint', 'flow', 'typescript', 'build.andTest', 'test')
82+
default: concurrent.nps(
83+
'lint',
84+
'flow',
85+
'typescript',
86+
'build.andTest',
87+
'test'
88+
)
7589
}
7690
},
7791
options: {

package.json

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-final-form",
3-
"version": "3.1.1",
3+
"version": "3.1.2",
44
"description":
55
"🏁 High performance subscription-based form state management for React",
66
"main": "dist/react-final-form.cjs.js",
@@ -26,7 +26,7 @@
2626
},
2727
"homepage": "https://github.com/final-form/react-final-form#readme",
2828
"devDependencies": {
29-
"@types/react": "^16.0.29",
29+
"@types/react": "^16.0.40",
3030
"babel-eslint": "^8.0.3",
3131
"babel-jest": "^22.4.1",
3232
"babel-plugin-external-helpers": "^6.22.0",
@@ -36,32 +36,33 @@
3636
"babel-preset-stage-2": "^6.24.1",
3737
"bundlesize": "^0.16.0",
3838
"doctoc": "^1.3.0",
39-
"eslint": "^4.18.1",
39+
"eslint": "^4.18.2",
4040
"eslint-config-react-app": "^2.1.0",
4141
"eslint-plugin-babel": "^4.1.2",
4242
"eslint-plugin-flowtype": "^2.46.1",
4343
"eslint-plugin-import": "^2.9.0",
4444
"eslint-plugin-jsx-a11y": "^6.0.2",
4545
"eslint-plugin-react": "^7.7.0",
46-
"final-form": "^4.2.1",
47-
"flow-bin": "^0.66.0",
46+
"final-form": "^4.3.0",
47+
"flow-bin": "^0.67.1",
48+
"glow": "^1.2.2",
4849
"husky": "^0.14.3",
4950
"jest": "^22.4.2",
5051
"lint-staged": "^7.0.0",
51-
"nps": "^5.7.1",
52+
"nps": "^5.8.2",
5253
"nps-utils": "^1.5.0",
5354
"opencollective": "^1.0.3",
54-
"prettier": "^1.8.2",
55+
"prettier": "^1.11.1",
5556
"prettier-eslint-cli": "^4.7.1",
56-
"prop-types": "^15.6.0",
57+
"prop-types": "^15.6.1",
5758
"raf": "^3.4.0",
5859
"react": "^16.2.0",
5960
"react-dom": "^16.2.0",
60-
"rollup": "^0.56.2",
61+
"rollup": "^0.56.5",
6162
"rollup-plugin-babel": "^3.0.2",
62-
"rollup-plugin-commonjs": "^8.2.6",
63+
"rollup-plugin-commonjs": "^9.1.0",
6364
"rollup-plugin-flow": "^1.1.1",
64-
"rollup-plugin-node-resolve": "^3.0.3",
65+
"rollup-plugin-node-resolve": "^3.2.0",
6566
"rollup-plugin-replace": "^2.0.0",
6667
"rollup-plugin-uglify": "^3.0.0",
6768
"tslint": "^5.9.1",

src/Field.js

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ const all: FieldSubscription = fieldSubscriptionItems.reduce((result, key) => {
1616
}, {})
1717

1818
type State = {
19-
state: FieldState
19+
state: ?FieldState
2020
}
2121

2222
export default class Field extends React.Component<Props, State> {
@@ -51,7 +51,7 @@ export default class Field extends React.Component<Props, State> {
5151
}
5252
})
5353
}
54-
this.state = { state: initialState || {} }
54+
this.state = { state: initialState }
5555
}
5656

5757
subscribe = (
@@ -96,20 +96,24 @@ export default class Field extends React.Component<Props, State> {
9696

9797
handlers = {
9898
onBlur: (event: ?SyntheticFocusEvent<*>) => {
99-
this.state.state.blur()
99+
this.state.state && this.state.state.blur()
100100
},
101101
onChange: (event: SyntheticInputEvent<*> | any) => {
102102
const { parse, value: _value } = this.props
103103
const value: any =
104104
event && event.target
105-
? getValue(event, this.state.state.value, _value, isReactNative)
105+
? getValue(
106+
event,
107+
this.state.state && this.state.state.value,
108+
_value,
109+
isReactNative
110+
)
106111
: event
107-
this.state.state.change(
108-
parse !== null ? parse(value, this.props.name) : value
109-
)
112+
this.state.state &&
113+
this.state.state.change(parse ? parse(value, this.props.name) : value)
110114
},
111115
onFocus: (event: ?SyntheticFocusEvent<*>) => {
112-
this.state.state.focus()
116+
this.state.state && this.state.state.focus()
113117
}
114118
}
115119

@@ -128,15 +132,9 @@ export default class Field extends React.Component<Props, State> {
128132
value: _value,
129133
...rest
130134
} = this.props
131-
let {
132-
blur,
133-
change,
134-
focus,
135-
value,
136-
name: ignoreName,
137-
...meta
138-
} = this.state.state
139-
if (format !== null) {
135+
let { blur, change, focus, value, name: ignoreName, ...meta } =
136+
this.state.state || {}
137+
if (format) {
140138
value = format(value, name)
141139
}
142140
if (value === null && !allowNull) {

src/FormSpy.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,9 @@ export default class FormSpy extends React.Component<Props, State> {
3737
}
3838
})
3939
}
40-
this.state = { state: initialState }
40+
if (initialState) {
41+
this.state = { state: initialState }
42+
}
4143
}
4244

4345
subscribe = (
@@ -86,7 +88,7 @@ export default class FormSpy extends React.Component<Props, State> {
8688
: renderComponent(
8789
{
8890
...rest,
89-
...this.state.state,
91+
...(this.state ? this.state.state : {}),
9092
mutators: reactFinalForm && reactFinalForm.mutators,
9193
batch: reactFinalForm && reactFinalForm.batch,
9294
blur: reactFinalForm && reactFinalForm.blur,

src/ReactFinalForm.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import type {
1717
import type { FormProps as Props, ReactContext } from './types'
1818
import shallowEqual from './shallowEqual'
1919
import renderComponent from './renderComponent'
20-
import { version } from './index'
20+
export const version = '3.1.0'
2121

2222
const versions = {
2323
'final-form': ffVersion,
@@ -94,7 +94,9 @@ export default class ReactFinalForm extends React.Component<Props, State> {
9494
}, subscription || all)
9595
)
9696
}
97-
this.state = { state: initialState }
97+
if (initialState) {
98+
this.state = { state: initialState }
99+
}
98100
if (decorators) {
99101
decorators.forEach(decorator => {
100102
this.unsubscriptions.push(decorator(this.form))
@@ -131,7 +133,10 @@ export default class ReactFinalForm extends React.Component<Props, State> {
131133
}
132134

133135
componentWillReceiveProps(nextProps: Props) {
134-
if (!shallowEqual(this.props.initialValues, nextProps.initialValues)) {
136+
if (
137+
nextProps.initialValues &&
138+
!shallowEqual(this.props.initialValues, nextProps.initialValues)
139+
) {
135140
this.form.initialize(nextProps.initialValues)
136141
}
137142
}
@@ -155,7 +160,7 @@ export default class ReactFinalForm extends React.Component<Props, State> {
155160
return renderComponent(
156161
{
157162
...props,
158-
...this.state.state,
163+
...(this.state ? this.state.state : {}),
159164
mutators: this.form && this.form.mutators,
160165
batch: this.form && this.form.batch,
161166
blur: this.form && this.form.blur,

src/index.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
// @flow
22
export { default as Field } from './Field'
3-
export { default as Form } from './ReactFinalForm'
3+
export { default as Form, version } from './ReactFinalForm'
44
export { default as FormSpy } from './FormSpy'
5-
export const version = '3.1.0'

src/types.js.flow

Lines changed: 28 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,12 @@ import type {
66
Decorator,
77
FormState,
88
FormSubscription,
9-
FieldSubscription
9+
FieldSubscription,
10+
FieldValidator
1011
} from 'final-form'
1112

13+
type SupportedInputs = 'input' | 'select' | 'textarea'
14+
1215
export type ReactContext = {
1316
reactFinalForm: FormApi
1417
}
@@ -21,22 +24,22 @@ export type FieldRenderProps = {
2124
onFocus: (?SyntheticFocusEvent<*>) => void,
2225
value: any
2326
},
24-
meta: $Shape<{
27+
meta: {
2528
// TODO: Make a diff of `FieldState` without all the functions
26-
active: boolean,
27-
dirty: boolean,
28-
dirtySinceLastSubmit: boolean,
29-
error: any,
30-
initial: boolean,
31-
invalid: boolean,
32-
pristine: boolean,
33-
submitError: any,
34-
submitFailed: boolean,
35-
submitSucceeded: boolean,
36-
touched: boolean,
37-
valid: boolean,
38-
visited: boolean
39-
}>
29+
active?: boolean,
30+
dirty?: boolean,
31+
dirtySinceLastSubmit?: boolean,
32+
error?: any,
33+
initial?: boolean,
34+
invalid?: boolean,
35+
pristine?: boolean,
36+
submitError?: any,
37+
submitFailed?: boolean,
38+
submitSucceeded?: boolean,
39+
touched?: boolean,
40+
valid?: boolean,
41+
visited?: boolean
42+
}
4043
}
4144

4245
export type SubsetFormApi = {
@@ -55,11 +58,11 @@ export type FormRenderProps = {
5558

5659
export type FormSpyRenderProps = SubsetFormApi & FormState
5760

58-
export type RenderableProps<T> = $Shape<{
59-
children: ((props: T) => React.Node) | React.Node,
60-
component: React.ComponentType<*>,
61-
render: (props: T) => React.Node
62-
}>
61+
export type RenderableProps<T> = {
62+
children?: ((props: T) => React.Node) | React.Node,
63+
component?: React.ComponentType<*> | string,
64+
render?: (props: T) => React.Node
65+
}
6366

6467
export type FormProps = {
6568
subscription?: FormSubscription,
@@ -69,12 +72,13 @@ export type FormProps = {
6972

7073
export type FieldProps = {
7174
allowNull?: boolean,
72-
format: ((value: any, name: string) => any) | null,
75+
component?: React.ComponentType<*> | SupportedInputs,
76+
format?: (value: any, name: string) => any,
7377
isEqual?: (a: any, b: any) => boolean,
7478
name: string,
75-
parse: ((value: any, name: string) => any) | null,
79+
parse?: (value: any, name: string) => any,
7680
subscription?: FieldSubscription,
77-
validate?: (value: ?any, allValues: Object) => ?any,
81+
validate?: FieldValidator,
7882
validateFields?: string[],
7983
value?: any
8084
} & RenderableProps<FieldRenderProps>

0 commit comments

Comments
 (0)