-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathupdate.js
75 lines (65 loc) · 1.68 KB
/
update.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import assert from 'assert'
import reduceReducers from 'reduce-reducers'
import { combineReducers } from 'redux'
import standardReducer from '../src/index'
/* eslint no-extra-semi: off */
describe('immutability-helper', function() {
let reducer
let state
beforeEach(() => {
reducer = reduceReducers(
standardReducer,
(state = { arr: [] }, action) => state,
combineReducers({
partial1(state = { value: 1, foo: 'bar-1' }, action) {
return state
},
partial2(state = { value: 2, foo: 'bar-2' }, action) {
return state
},
})
)
// init
state = {}
state = reducer(state, { type: 'init' })
state.partial1.value.should.equal(1)
state.partial2.value.should.equal(2)
})
it('it works', function() {
const oldPartial2 = state.partial2
state = reducer(state, {
type: 'UPDATE_PARTIAL_1',
standard: true,
update: {
partial1: {
foo: { $set: 'updated-foo-1' },
},
},
})
state.partial1.foo.should.equal('updated-foo-1')
// partial2 should not change
assert(state.partial2 === oldPartial2)
// init `partial1.sub` to object
state = reducer(state, {
type: 'UPDATE_PARTIAL_1',
standard: true,
update: {
partial1: {
sub: {
$apply: sub => sub || {},
},
},
},
})
assert(state.partial1.sub)
})
it('throws when `action.update` not object', function() {
;(() => {
state = reducer(state, {
type: 'SOME_ACTION_TYPE',
standard: true,
update: 1,
})
}).should.throw(/expect standard action.update = object/)
})
})