-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
/
index.js
44 lines (41 loc) · 1.38 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
// @flow
import { Map, Iterable, List, fromJS } from 'immutable'
import { toPath } from 'lodash'
import deepEqual from './deepEqual'
import keys from './keys'
import setIn from './setIn'
import splice from './splice'
import plainGetIn from '../plain/getIn'
import type { Structure } from '../../types'
import type { Map as ImmutableMap, List as ImmutableList } from 'immutable'
const emptyList = List()
const structure: Structure<ImmutableMap<string, *>, ImmutableList<*>> = {
allowsArrayErrors: false,
empty: Map(),
emptyList,
getIn: (state: ImmutableMap<string, *> | ImmutableList<*>, field: string) =>
Iterable.isIterable(state)
? state.getIn(toPath(field))
: plainGetIn(state, field),
setIn,
deepEqual,
deleteIn: (
state: ImmutableMap<string, *> | ImmutableList<*>,
field: string
) => state.deleteIn(toPath(field)),
forEach: (items, callback) => {
items.forEach(callback)
},
fromJS: jsValue =>
fromJS(jsValue, (key, value) =>
Iterable.isIndexed(value) ? value.toList() : value.toMap()
),
keys,
size: list => (list ? list.size : 0),
some: (items, callback) => items.some(callback),
splice,
equals: (a, b) => (b.equals(a) ? true : b.toSet().equals(a.toSet())),
orderChanged: (a, b) => b.some((val, index) => val !== a.get(index)),
toJS: value => (Iterable.isIterable(value) ? value.toJS() : value)
}
export default structure