Skip to content
Myr

fix: fixed issue where new items in Set where not recorded after iterating. Fixes #586

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Michel Weststrate · committed by Michel Weststrate · parent 8d4e0de · Browse files · 2 files+11 added−3 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+11 added−3 removed

  • tests:+10 added−0 removed
  • other:+1 added−3 removed

2 files+11 added−3 removed

modified:__tests__/map-set.js+10 added
223 unmodified lines
224 value: true225 }226 ])227 })228229 test("#586", () => {230 const base = new Set([1, 2])231 const set = produce(base, draftSet => {232 debugger233 expect(Array.from(draftSet)).toEqual([1, 2])234 draftSet.add(3)235 })236 expect(Array.from(set).sort()).toEqual([1, 2, 3])237 })238 })239}
modified:src/plugins/mapset.ts+1 added-3 removed
239 unmodified lines
240241 p.add = function(value: any): any {242 const state: SetState = this[DRAFT_STATE]243 assertUnrevoked(state)244 if (state.copy_) {245 state.copy_.add(value)246 } else if (!state.base_.has(value)) {244 if (!this.has(value)) {245 prepareSetCopy(state)246 markChanged(state.scope_.immer_, state)247 state.copy_!.add(value)248 }
89 unmodified lines