Skip to content
Myr

fixed remaining tests, fixes #466

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 385c0a4 · Browse files · 6 files+64 added−19 removed
This commit

State

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

Diff stats

6 files+64 added−19 removed

  • tests:+48 added−14 removed
  • other:+16 added−5 removed

6 files+64 added−19 removed

modified:__tests__/base.js+13 added
717 unmodified lines
718 expect(result).not.toBe(base)719 expect(base).toEqual(new Set([new Set(["Serenity"])]))720 expect(result).toEqual(new Set([new Set(["Serenity", "Firefly"])]))721 })722723 it("supports has / delete on elements from the original", () => {724 const obj = {}725 const set = new Set([obj])726 const next = produce(set, d => {727 expect(d.has(obj)).toBe(true)728 d.add(3)729 expect(d.has(obj)).toBe(true)730 d.delete(obj)731 expect(d.has(obj)).toBe(false)732 })733 expect(next).toEqual(new Set([3]))734 })735 })736737 it("supports `immerable` symbol on constructor", () => {738 class One {}
1055 unmodified lines
modified:__tests__/hooks.js+1 added-1 removed
157 unmodified lines
158 expectCalls(onAssign)159 })160 })161162 describe.skip("when draft is a Set", () => {162 describe("when draft is a Set", () => {163 test("assign", () => {164 produce({a: new Set([1, 2, 3])}, s => {165 s.a.add(4)166 })
195 unmodified lines
modified:__tests__/map-set.js+32 added-11 removed
modified:__tests__/patch.js+2 added-2 removed
616 unmodified lines
617 []618 )619})620621describe.skip("sets - mutate - 1", () => {621describe.only("sets - mutate - 1", () => {622 const findById = (set, id) => {623 for (const item of set) {624 if (item.id === id) return item625 }
102 unmodified lines
728 []729 )730})731732describe.skip("same value replacement - 6", () => {732describe("same value replacement - 6", () => {733 runPatchTest(734 new Set(["x", 3]),735 d => {736 d.delete("x")
127 unmodified lines
modified:src/immer.ts+1 added-1 removed
378 unmodified lines
379 scope.canAutoFreeze = false380 }381382 // Unchanged drafts are never passed to the `onAssign` hook.383 if (isDraftProp && !isSetMember && value === get(state.base, prop)) return383 if (isDraftProp && !isSet && value === get(state.base, prop)) return384 }385 // Unchanged draft properties are ignored.386 else if (isDraftProp && is(value, get(state.base, prop))) {387 return
40 unmodified lines
modified:src/set.ts+15 added-4 removed
34 unmodified lines
35 finalized: boolean;36 copy: Set<any> | undefined;37 // assigned: Map<any, boolean> | undefined;38 base: Set<any>;39 drafts: Map<any, any>; // maps the original value to the draft value in the new set40 revoke(): void;41 draft: ES5Draft;42}43
1 unmodified line
45 if (!state.copy) {46 // create drafts for all entries to preserve insertion order47 state.copy = new Set()48 state.base.forEach(value => {48 state.copy!.add(state.scope.immer.createProxy(value, state))49 const draft = state.scope.immer.createProxy(value, state);50 state.copy!.add(draft)51 state.drafts.set(value, draft)52 })53 }54}55
13 unmodified lines
69 finalizing: false,70 copy: undefined,71 base: target,72 draft: this as any, // TODO: fix typing73 drafts: new Map(),74 revoke() {75 // TODO: make sure this marks the Map as revoked, and assert everywhere76 }77 };
3 unmodified lines
81 return latest(this[DRAFT_STATE]).size82 }8384 has(value: V): boolean {81 return latest(this[DRAFT_STATE]).has(value)85 const state = this[DRAFT_STATE]86 // bit of trickery here, to be able to recognize both the value, and the draft of its value87 if (!state.copy) {88 return state.base.has(value)89 }90 if (state.copy.has(value)) return true;91 if (state.drafts.has(value) && state.copy.has(state.drafts.get(value))) return true;92 return false;93 }9495 add(value: V): this {96 const state = this[DRAFT_STATE];
7 unmodified lines
104 return this105 }106107 delete(value: V): boolean {108 const state = this[DRAFT_STATE];109 if (!this.has(value)) {110 return false;111 }112101 const state = this[DRAFT_STATE];113 prepareCopy(state)114 state.scope.immer.markChanged(state)104 return state.copy!.delete(value)115 return state.copy!.delete(value) || (state.drafts.has(value) ? state.copy!.delete(state.drafts.get(value)) : false)116 }117118 clear() {119 const state = this[DRAFT_STATE];
64 unmodified lines