Skip to content

Commit

Permalink
Upgrade immer to v2
Browse files Browse the repository at this point in the history
  • Loading branch information
cjies committed Apr 11, 2019
1 parent 1c3b74b commit 69f0060
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 5 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"test": "NODE_ENV=test ava"
},
"dependencies": {
"immer": "^1.3.0"
"immer": "^2.1.5"
},
"devDependencies": {
"@babel/core": "^7.4.3",
Expand Down
38 changes: 37 additions & 1 deletion src/duck.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ test('export methods', t => {
t.is(typeof duck.createReducer, 'function', 'it should be a function');
});

test('Create action type', t => {
test('create action type', t => {
const TYPE_1 = duck.defineType('test1', 'TYPE'); // `test1` as prefix
const TYPE_2 = duck.defineType('TYPE_2');

Expand Down Expand Up @@ -136,3 +136,39 @@ test('throw error if try to mutate reducer state', t => {
);
t.is(error2.message, 'Cannot add property id, object is not extensible');
});

// Test with Classes & Symbol
test('support Classes & Symbol in reducer', t => {
class ClassA {}
class ClassB extends ClassA {}
const SymbolA = Symbol('a');

const UPDATE_CLASS_N_SYMBOL = duck.defineType('UPDATE_CLASS_N_SYMBOL');
const updateClassNSymbol = {
type: UPDATE_CLASS_N_SYMBOL,
payload: {
class: new ClassB(),
symbol: SymbolA,
},
};

const initState = {
class: new ClassA(),
symbol: undefined,
};
const testReducer = duck.createReducer(initState, {
[UPDATE_CLASS_N_SYMBOL]: (state, action) => {
return action.payload;
},
});
const testState = testReducer(initState, updateClassNSymbol);

t.deepEqual(
testState,
{
class: new ClassB(),
symbol: SymbolA,
},
'the reducer should work with Classes & Symbol'
);
});
7 changes: 4 additions & 3 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2070,9 +2070,10 @@ ignore@^3.3.7:
version "3.3.8"
resolved "https://registry.yarnpkg.com/ignore/-/ignore-3.3.8.tgz#3f8e9c35d38708a3a7e0e9abb6c73e7ee7707b2b"

immer@^1.3.0:
version "1.3.0"
resolved "https://registry.yarnpkg.com/immer/-/immer-1.3.0.tgz#b5c462dad2a129ad909eb4a180de63ffaa348d12"
immer@^2.1.5:
version "2.1.5"
resolved "https://registry.yarnpkg.com/immer/-/immer-2.1.5.tgz#0389947455c5a2c7a47f1e6f415c9d1a62a1ebed"
integrity sha512-xyjQyTBYIeiz6jd02Hg12jV+9QISwF1crLcwTlzHpWH4e0ryNWj1kacpTwimK3bJV5NKKXw458G2vpqoB/inFA==

import-fresh@^2.0.0:
version "2.0.0"
Expand Down

0 comments on commit 69f0060

Please sign in to comment.