Skip to content

Commit

Permalink
Adds update functionality to Map entries (#100)
Browse files Browse the repository at this point in the history
Resolves issue #89 by supporting the Map set syntax in the update
function.
  • Loading branch information
Matthew Keibler authored and kolodny committed Mar 22, 2018
1 parent d9c800c commit e5e6252
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
6 changes: 5 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,11 @@ function newContext() {
if (nextObject === object) {
nextObject = copy(object);
}
nextObject[key] = nextValueForKey;
if (type(nextObject) === 'Map') {
nextObject.set(key, nextValueForKey);
} else {
nextObject[key] = nextValueForKey;
}
}
}
})
Expand Down
16 changes: 16 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -529,4 +529,20 @@ describe('update', function() {
expect(state2.items.top).toBe(0)
});

it('supports Maps', function() {
var state = new Map([
['mapKey', 'mapValue']
]);

var updatedState = update(state, {
['mapKey']: {$set: 'updatedMapValue' }
});

expect(updatedState).toEqual(
new Map([
['mapKey', 'updatedMapValue']
])
);
});

});

0 comments on commit e5e6252

Please sign in to comment.