Skip to content

Commit

Permalink
Support set on Maps
Browse files Browse the repository at this point in the history
  • Loading branch information
Moshe Kolodny committed Jun 13, 2019
1 parent 1f7f0cf commit c60fdba
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
language: node_js
node_js:
- '6'
- '8'
- '10'
- '12'
- 'lts/*'
# Send coverage data to Coveralls
after_script: "cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js"
4 changes: 4 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ declare type MapSpec<K, V> = {
$add: Array<[K, V]>;
} | {
$remove: K[];
} | {
[key: string]: {
$set: V;
};
};
declare type SetSpec<T> = {
$add: T[];
Expand Down
3 changes: 2 additions & 1 deletion index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,8 @@ type ArraySpec<T, C extends CustomCommands<object>> =

type MapSpec<K, V> =
| { $add: Array<[K, V]> }
| { $remove: K[] };
| { $remove: K[] }
| { [key: string]: { $set: V } };

type SetSpec<T> =
| { $add: T[] }
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "immutability-helper",
"version": "3.0.0",
"version": "3.0.1",
"description": "mutate a copy of data without changing the original source",
"main": "index.js",
"typings": "index.d.ts",
Expand Down
7 changes: 7 additions & 0 deletions test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,13 @@ describe('immutability-helper module', () => {
expect(result).toEqual({a: 1, b: undefined});
expect(Object.keys(result).length).toEqual(2);
});
it('works on Map (E2E)', () => {
const state = new Map([['foo', 'FOO'], ['bar', 'BAR']]);
const modified = update(state, {foo: {$set: 'OFO' }});
expect(state).toEqual(new Map([['foo', 'FOO'], ['bar', 'BAR']]));
expect(modified).toEqual(new Map([['foo', 'OFO'], ['bar', 'BAR']]));
expect(state).not.toBe(modified);
});
});

describe('$toggle', () => {
Expand Down

0 comments on commit c60fdba

Please sign in to comment.