Skip to content

Commit

Permalink
fix: fixed issue where new items in Set where not recorded after iter…
Browse files Browse the repository at this point in the history
…ating. Fixes #586
  • Loading branch information
mweststrate committed May 23, 2020
1 parent 8d4e0de commit 169db77
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
10 changes: 10 additions & 0 deletions __tests__/map-set.js
Expand Up @@ -225,5 +225,15 @@ function runBaseTest(name, useProxies, autoFreeze, useListener) {
}
])
})

test("#586", () => {
const base = new Set([1, 2])
const set = produce(base, draftSet => {
debugger
expect(Array.from(draftSet)).toEqual([1, 2])
draftSet.add(3)
})
expect(Array.from(set).sort()).toEqual([1, 2, 3])
})
})
}
4 changes: 1 addition & 3 deletions src/plugins/mapset.ts
Expand Up @@ -241,9 +241,7 @@ export function enableMapSet() {
p.add = function(value: any): any {
const state: SetState = this[DRAFT_STATE]
assertUnrevoked(state)
if (state.copy_) {
state.copy_.add(value)
} else if (!state.base_.has(value)) {
if (!this.has(value)) {
prepareSetCopy(state)
markChanged(state.scope_.immer_, state)
state.copy_!.add(value)
Expand Down

0 comments on commit 169db77

Please sign in to comment.