Skip to content

Commit a4d62c0

Browse files
authored
Support pushing multiple values to the List (#99)
1 parent fb044e4 commit a4d62c0

File tree

6 files changed

+18
-13
lines changed

6 files changed

+18
-13
lines changed

.size-snapshot.json

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
{
22
"dist/react-powerplug.umd.js": {
3-
"bundled": 24029,
4-
"minified": 9906,
5-
"gzipped": 2565
3+
"bundled": 24183,
4+
"minified": 9975,
5+
"gzipped": 2574
66
},
77
"dist/react-powerplug.cjs.js": {
8-
"bundled": 20918,
9-
"minified": 10782,
10-
"gzipped": 2414
8+
"bundled": 21066,
9+
"minified": 10851,
10+
"gzipped": 2438
1111
},
1212
"dist/react-powerplug.esm.js": {
13-
"bundled": 20272,
14-
"minified": 10233,
15-
"gzipped": 2286,
13+
"bundled": 20420,
14+
"minified": 10302,
15+
"gzipped": 2310,
1616
"treeshaked": {
1717
"rollup": 1489,
1818
"webpack": 1939

docs/components/List.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ Get first element of your list array
4747
Get last element of your list array
4848

4949
**push**
50-
`(item: any) => void`
51-
Add an item to your list array
50+
`(item1: any, item2: any, ...) => void`
51+
Add an items to your list array
5252

5353
**pull**
5454
`(predicate: (item: any) => boolean) => void`

src/components/List.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ const List = ({ initial = [], onChange, ...props }) => (
1313
first: () => state.list[0],
1414
last: () => state.list[Math.max(0, state.list.length - 1)],
1515
set: list => setState(s => ({ list: set(list, s.list) })),
16-
push: value => setState(s => ({ list: [...s.list, value] })),
16+
push: (...values) => setState(s => ({ list: [...s.list, ...values] })),
1717
pull: predicate =>
1818
setState(s => ({ list: s.list.filter(complement(predicate)) })),
1919
sort: compareFn =>

src/index.js.flow

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ type ListRender<T> = ({|
135135
first: () => T | void,
136136
last: () => T | void,
137137
set: Updater<$ReadOnlyArray<T>>,
138-
push: (value: T) => void,
138+
push: (...values: $ReadOnlyArray<T>) => void,
139139
pull: (predicate: (T) => boolean) => void,
140140
sort: (compare: (a: T, b: T) => -1 | 0 | 1) => void,
141141
|}) => React.Node

tests/components/List.test.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,8 @@ test('<List />', () => {
3434
lastCalled().set([])
3535
expect(lastCalled().first()).toEqual(undefined)
3636
expect(lastCalled().last()).toEqual(undefined)
37+
38+
// support pushing many array
39+
lastCalled().push(1, 2, 3)
40+
expect(lastCalled().list).toEqual([1, 2, 3])
3741
})

tests/test_flow.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,7 @@ const noop = () => null
292292
set([])
293293
set([0])
294294
push(0)
295+
push(0, 1, 2)
295296
pull((d: number) => true)
296297
sort((a: number, b: number) => -1)
297298
// $FlowFixMe

0 commit comments

Comments
 (0)