Skip to content
Myr

Merge branch 'fix-472' of https://github.com/oriSomething/immer into oriSomething-fix-472

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 · parents c1432fa, 0020809 · Browse files · 5 files+45 added−9 removed
This commit

State

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

Diff stats

5 files+45 added−9 removed

  • tests:+36 added−7 removed
  • other:+9 added−2 removed

5 files+45 added−9 removed

modified:__tests__/__snapshots__/manual.js.snap+2 added-2 removed
48 unmodified lines
49 ],50]51`;5253exports[`manual - proxy cannot modify after finish 1`] = `"Cannot use a proxy that has been revoked. Did you pass an object from inside an immer function to an async process? {\\"a\\":2}"`;53exports[`manual - proxy cannot modify after finish 1`] = `"Cannot perform 'set' on a proxy that has been revoked"`;5455exports[`manual - proxy should check arguments 1`] = `"First argument to \`createDraft\` must be a plain object, an array, or an immerable object"`;5657exports[`manual - proxy should check arguments 2`] = `"First argument to \`createDraft\` must be a plain object, an array, or an immerable object"`;
1 unmodified line
59exports[`manual - proxy should check arguments 3`] = `"First argument to \`finishDraft\` must be a draft returned by \`createDraft\`"`;6061exports[`manual - proxy should not finish drafts from produce 1`] = `"First argument to \`finishDraft\` must be a draft returned by \`createDraft\`"`;6263exports[`manual - proxy should not finish twice 1`] = `"The given draft is already finalized"`;63exports[`manual - proxy should not finish twice 1`] = `"Cannot perform 'get' on a proxy that has been revoked"`;6465exports[`manual - proxy should support patches drafts 1`] = `66Array [67 Array [
34 unmodified lines
modified:__tests__/curry.js+3 added-1 removed
modified:__tests__/frozen.js+28 added-3 removed
6 unmodified lines
7runTests("es5", false)89function runTests(name, useProxies) {10 describe("auto freeze - " + name, () => {11 beforeAll(() => {11 setUseProxies(useProxies)12 setAutoFreeze(true)12 setUseProxies(useProxies)13 setAutoFreeze(true)14 })1516 it("never freezes the base state", () => {17 const base = {arr: [1], obj: {a: 1}}18 const next = produce(base, draft => {
118 unmodified lines
137 })138139 it("will freeze maps", () => {140 const base = new Map()139 debugger141142 const res = produce(base, draft => {143 draft.set("a", 1)144 })145 expect(() => res.set("b", 2)).toThrow(
27 unmodified lines
173174 // In draft, still editable175 expect(produce(res, d => void d.add(2))).not.toBe(res)176 })177178 it("Map#get() of frozen object will became draftable", () => {179 const base = {180 map: new Map([181 ["a", new Map([["a", true], ["b", true], ["c", true]])],182 ["b", new Map([["a", true]])],183 ["c", new Map([["a", true]])]184 ])185 }186187 // This will freeze maps188 const frozen = produce(base, draft => {})189190 // https://github.com/immerjs/immer/issues/472191 produce(frozen, draft => {192 // if (useProxies) debugger193 ;["b", "c"].forEach(other => {194 const m = draft.map.get(other)195196 m.delete("a")197 })198 })199 })200 })201}
modified:__tests__/manual.js+3 added-1 removed
10 unmodified lines
11runTests("es5", false)1213function runTests(name, useProxies) {14 describe("manual - " + name, () => {15 beforeAll(() => {15 setUseProxies(useProxies)16 setUseProxies(useProxies)17 })1819 it("should check arguments", () => {20 expect(() => createDraft(3)).toThrowErrorMatchingSnapshot()21 const buf = new Buffer([])
117 unmodified lines
modified:src/proxy.js+9 added-2 removed
240 unmodified lines
241 const value = receiver.get(key)242 cb.call(thisArg, value, key, map)243 }),244 get: state => key => {245 const drafts = state[state.modified ? "copy" : "drafts"]245 const drafts = state.modified ? state.copy : state.drafts246247 if (drafts.has(key)) {247 return drafts.get(key)248 const value = drafts.get(key)249250 if (isDraft(value) || !isDraftable(value)) return value251252 const draft = createProxy(value, state)253 drafts.set(key, draft)254 return draft255 }256257 const value = latest(state).get(key)258 if (state.finalized || !isDraftable(value)) {
116 unmodified lines