Skip to content

Commit 913c961

Browse files
authored
Fixed flow errors (#32)
1 parent ae34dbe commit 913c961

21 files changed

+3627
-6876
lines changed

package-lock.json

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

package.json

Lines changed: 30 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -25,54 +25,55 @@
2525
},
2626
"homepage": "https://github.com/final-form/final-form-arrays#readme",
2727
"devDependencies": {
28-
"@babel/core": "^7.0.0",
28+
"@babel/core": "^7.5.4",
2929
"@babel/plugin-external-helpers": "^7.0.0",
30-
"@babel/plugin-proposal-class-properties": "^7.0.0",
31-
"@babel/plugin-proposal-decorators": "^7.0.0",
32-
"@babel/plugin-proposal-export-namespace-from": "^7.0.0",
33-
"@babel/plugin-proposal-function-sent": "^7.0.0",
30+
"@babel/plugin-proposal-class-properties": "^7.5.0",
31+
"@babel/plugin-proposal-decorators": "^7.4.4",
32+
"@babel/plugin-proposal-export-namespace-from": "^7.5.2",
33+
"@babel/plugin-proposal-function-sent": "^7.5.0",
3434
"@babel/plugin-proposal-json-strings": "^7.0.0",
3535
"@babel/plugin-proposal-numeric-separator": "^7.0.0",
3636
"@babel/plugin-proposal-throw-expressions": "^7.0.0",
3737
"@babel/plugin-syntax-dynamic-import": "^7.0.0",
3838
"@babel/plugin-syntax-import-meta": "^7.0.0",
39-
"@babel/plugin-transform-flow-strip-types": "^7.0.0",
40-
"@babel/plugin-transform-runtime": "^7.2.0",
41-
"@babel/preset-env": "^7.0.0",
39+
"@babel/plugin-transform-flow-strip-types": "^7.4.4",
40+
"@babel/plugin-transform-runtime": "^7.5.0",
41+
"@babel/preset-env": "^7.5.4",
4242
"@babel/preset-flow": "^7.0.0",
4343
"babel-core": "^7.0.0-bridge.0",
44-
"babel-eslint": "^10.0.1",
45-
"babel-jest": "^23.4.2",
46-
"bundlesize": "^0.17.1",
44+
"babel-eslint": "^10.0.2",
45+
"babel-jest": "^24.8.0",
46+
"bundlesize": "^0.18.0",
4747
"doctoc": "^1.3.0",
48-
"eslint": "^5.13.0",
48+
"eslint": "^6.0.1",
4949
"eslint-config-react-app": "^3.0.6",
50-
"eslint-plugin-babel": "^5.1.0",
50+
"eslint-plugin-babel": "^5.3.0",
5151
"eslint-plugin-flowtype": "^3.2.1",
5252
"eslint-plugin-import": "^2.16.0",
5353
"eslint-plugin-jsx-a11y": "^6.2.1",
54-
"eslint-plugin-react": "^7.12.4",
55-
"final-form": "^4.11.1",
56-
"flow-bin": "^0.92.1",
54+
"eslint-plugin-react": "^7.13.0",
55+
"final-form": "^4.17.0",
56+
"flow-bin": "^0.102.0",
5757
"glow": "^1.2.2",
58-
"husky": "^1.3.1",
59-
"jest": "^24.1.0",
60-
"lint-staged": "^8.1.3",
61-
"nps": "^5.7.1",
58+
"husky": "^3.0.0",
59+
"jest": "^24.8.0",
60+
"lint-staged": "^9.2.0",
61+
"nps": "^5.9.5",
6262
"nps-utils": "^1.5.0",
63-
"prettier": "^1.16.4",
64-
"prettier-eslint-cli": "^4.7.0",
65-
"rollup": "^1.1.2",
66-
"rollup-plugin-babel": "^4.3.2",
67-
"rollup-plugin-commonjs": "^9.1.5",
63+
"prettier": "^1.18.2",
64+
"prettier-eslint-cli": "^5.0.0",
65+
"react": "^16.8.6",
66+
"rollup": "^1.16.7",
67+
"rollup-plugin-babel": "^4.3.3",
68+
"rollup-plugin-commonjs": "^10.0.1",
6869
"rollup-plugin-flow": "^1.1.1",
69-
"rollup-plugin-node-resolve": "^4.0.0",
70-
"rollup-plugin-replace": "^2.0.0",
70+
"rollup-plugin-node-resolve": "^5.2.0",
71+
"rollup-plugin-replace": "^2.2.0",
7172
"rollup-plugin-uglify": "^6.0.2",
72-
"typescript": "^3.3.1"
73+
"typescript": "^3.5.3"
7374
},
7475
"peerDependencies": {
75-
"final-form": ">=1.2.0"
76+
"final-form": "^4.17.0"
7677
},
7778
"lint-staged": {
7879
"*.{js*,ts*,json,md,css}": [

src/concat.js

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
11
// @flow
22
import type { MutableState, Mutator, Tools } from 'final-form'
33

4-
const concat: Mutator = (
4+
const concat: Mutator<any> = (
55
[name, value]: any[],
6-
state: MutableState,
7-
{ changeValue }: Tools
6+
state: MutableState<any>,
7+
{ changeValue }: Tools<any>
88
) => {
9-
changeValue(
10-
state,
11-
name,
12-
(array: ?(any[])): any[] => (array ? [...array, ...value] : value)
9+
changeValue(state, name, (array: ?(any[])): any[] =>
10+
array ? [...array, ...value] : value
1311
)
1412
}
1513

src/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import swap from './swap'
1212
import unshift from './unshift'
1313
import update from './update'
1414

15-
const mutators: { [string]: Mutator } = {
15+
const mutators: { [string]: Mutator<any> } = {
1616
insert,
1717
concat,
1818
move,

src/index.js.flow

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// @flow
22
import type { Mutator } from 'final-form'
33

4-
type DefaultType = { [string]: Mutator }
4+
type DefaultType = { [string]: Mutator<any> }
55

66
declare export default DefaultType
77

src/insert.js

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,16 @@
11
// @flow
22
import type { MutableState, Mutator, Tools } from 'final-form'
33

4-
const insert: Mutator = (
4+
const insert: Mutator<any> = (
55
[name, index, value]: any[],
6-
state: MutableState,
7-
{ changeValue }: Tools
6+
state: MutableState<any>,
7+
{ changeValue }: Tools<any>
88
) => {
9-
changeValue(
10-
state,
11-
name,
12-
(array: ?(any[])): any[] => {
13-
const copy = [...(array || [])]
14-
copy.splice(index, 0, value)
15-
return copy
16-
}
17-
)
9+
changeValue(state, name, (array: ?(any[])): any[] => {
10+
const copy = [...(array || [])]
11+
copy.splice(index, 0, value)
12+
return copy
13+
})
1814

1915
// now we have increment any higher indexes
2016
const pattern = new RegExp(`^${name}\\[(\\d+)\\](.*)`)
@@ -28,6 +24,7 @@ const insert: Mutator = (
2824
const incrementedKey = `${name}[${fieldIndex + 1}]${tokens[2]}`
2925
changes[incrementedKey] = state.fields[key]
3026
changes[incrementedKey].name = incrementedKey
27+
changes[incrementedKey].forceUpdate = true
3128
}
3229
if (fieldIndex === index) {
3330
delete state.fields[key]

src/insert.test.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -133,17 +133,20 @@ describe('insert', () => {
133133
'foo[2]': {
134134
name: 'foo[2]',
135135
touched: false,
136-
error: 'B Error'
136+
error: 'B Error',
137+
forceUpdate: true
137138
},
138139
'foo[3]': {
139140
name: 'foo[3]',
140141
touched: true,
141-
error: 'C Error'
142+
error: 'C Error',
143+
forceUpdate: true
142144
},
143145
'foo[4]': {
144146
name: 'foo[4]',
145147
touched: false,
146-
error: 'D Error'
148+
error: 'D Error',
149+
forceUpdate: true
147150
}
148151
}
149152
})

src/move.js

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,21 @@
11
// @flow
22
import type { MutableState, Mutator, Tools } from 'final-form'
33

4-
const move: Mutator = (
4+
const move: Mutator<any> = (
55
[name, from, to]: any[],
6-
state: MutableState,
7-
{ changeValue }: Tools
6+
state: MutableState<any>,
7+
{ changeValue }: Tools<any>
88
) => {
99
if (from === to) {
1010
return
1111
}
12-
changeValue(
13-
state,
14-
name,
15-
(array: ?(any[])): any[] => {
16-
const copy = [...(array || [])]
17-
const value = copy[from]
18-
copy.splice(from, 1)
19-
copy.splice(to, 0, value)
20-
return copy
21-
}
22-
)
12+
changeValue(state, name, (array: ?(any[])): any[] => {
13+
const copy = [...(array || [])]
14+
const value = copy[from]
15+
copy.splice(from, 1)
16+
copy.splice(to, 0, value)
17+
return copy
18+
})
2319
const fromPrefix = `${name}[${from}]`
2420
Object.keys(state.fields).forEach(key => {
2521
if (key.substring(0, fromPrefix.length) === fromPrefix) {
@@ -65,6 +61,7 @@ const move: Mutator = (
6561
change: state.fields[destKey] && state.fields[destKey].change,
6662
blur: state.fields[destKey] && state.fields[destKey].blur,
6763
focus: state.fields[destKey] && state.fields[destKey].focus,
64+
forceUpdate: true,
6865
lastFieldState: undefined // clearing lastFieldState forces renotification
6966
}
7067
}

src/move.test.js

Lines changed: 34 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -97,19 +97,22 @@ describe('move', () => {
9797
name: 'foo[0]',
9898
touched: true,
9999
error: 'Error B',
100-
lastFieldState: undefined
100+
lastFieldState: undefined,
101+
forceUpdate: true
101102
},
102103
'foo[1]': {
103104
name: 'foo[1]',
104105
touched: false,
105106
error: 'Error C',
106-
lastFieldState: undefined
107+
lastFieldState: undefined,
108+
forceUpdate: true
107109
},
108110
'foo[2]': {
109111
name: 'foo[2]',
110112
touched: true,
111113
error: 'Error A',
112-
lastFieldState: undefined
114+
lastFieldState: undefined,
115+
forceUpdate: true
113116
},
114117
'foo[3]': {
115118
name: 'foo[3]',
@@ -173,19 +176,22 @@ describe('move', () => {
173176
name: 'foo[0]',
174177
touched: false,
175178
error: 'Error C',
176-
lastFieldState: undefined
179+
lastFieldState: undefined,
180+
forceUpdate: true
177181
},
178182
'foo[1]': {
179183
name: 'foo[1]',
180184
touched: true,
181185
error: 'Error A',
182-
lastFieldState: undefined
186+
lastFieldState: undefined,
187+
forceUpdate: true
183188
},
184189
'foo[2]': {
185190
name: 'foo[2]',
186191
touched: true,
187192
error: 'Error B',
188-
lastFieldState: undefined
193+
lastFieldState: undefined,
194+
forceUpdate: true
189195
},
190196
'foo[3]': {
191197
name: 'foo[3]',
@@ -259,7 +265,7 @@ describe('move', () => {
259265
}
260266
}
261267
move(['foo', 0, 2], state, { changeValue })
262-
expect(state).toEqual({
268+
expect(state).toMatchObject({
263269
formState: {
264270
values: {
265271
foo: [
@@ -274,7 +280,8 @@ describe('move', () => {
274280
'foo[0].dog': {
275281
name: 'foo[0].dog',
276282
touched: true,
277-
error: 'Error B Dog'
283+
error: 'Error B Dog',
284+
forceUpdate: true
278285
},
279286
'foo[0].cat': {
280287
name: 'foo[0].cat',
@@ -294,12 +301,14 @@ describe('move', () => {
294301
'foo[2].dog': {
295302
name: 'foo[2].dog',
296303
touched: true,
297-
error: 'Error A Dog'
304+
error: 'Error A Dog',
305+
forceUpdate: true
298306
},
299307
'foo[2].cat': {
300308
name: 'foo[2].cat',
301309
touched: false,
302-
error: 'Error A Cat'
310+
error: 'Error A Cat',
311+
forceUpdate: true
303312
},
304313
'foo[3].dog': {
305314
name: 'foo[3].dog',
@@ -377,7 +386,7 @@ describe('move', () => {
377386
}
378387
}
379388
move(['foo', 2, 0], state, { changeValue })
380-
expect(state).toEqual({
389+
expect(state).toMatchObject({
381390
formState: {
382391
values: {
383392
foo: [
@@ -392,12 +401,14 @@ describe('move', () => {
392401
'foo[0].dog': {
393402
name: 'foo[0].dog',
394403
touched: true,
395-
error: 'Error C Dog'
404+
error: 'Error C Dog',
405+
forceUpdate: true
396406
},
397407
'foo[0].cat': {
398408
name: 'foo[0].cat',
399409
touched: false,
400-
error: 'Error C Cat'
410+
error: 'Error C Cat',
411+
forceUpdate: true
401412
},
402413
'foo[1].dog': {
403414
name: 'foo[1].dog',
@@ -412,12 +423,14 @@ describe('move', () => {
412423
'foo[2].dog': {
413424
name: 'foo[2].dog',
414425
touched: true,
415-
error: 'Error B Dog'
426+
error: 'Error B Dog',
427+
forceUpdate: true
416428
},
417429
'foo[2].cat': {
418430
name: 'foo[2].cat',
419431
touched: true,
420-
error: 'Error B Cat'
432+
error: 'Error B Cat',
433+
forceUpdate: true
421434
},
422435
'foo[3].dog': {
423436
name: 'foo[3].dog',
@@ -475,17 +488,20 @@ describe('move', () => {
475488
'foo[0].dog': {
476489
name: 'foo[0].dog',
477490
touched: true,
478-
error: 'Error B Dog'
491+
error: 'Error B Dog',
492+
forceUpdate: true
479493
},
480494
'foo[1].dog': {
481495
name: 'foo[1].dog',
482496
touched: true,
483-
error: 'Error A Dog'
497+
error: 'Error A Dog',
498+
forceUpdate: true
484499
},
485500
'foo[1].cat': {
486501
name: 'foo[1].cat',
487502
touched: false,
488-
error: 'Error A Cat'
503+
error: 'Error A Cat',
504+
forceUpdate: true
489505
}
490506
}
491507
})

0 commit comments

Comments
 (0)