Skip to content
Myr

chores: added additional invariants

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 c6cd632 · Browse files · 3 files+28 added−1 removed
This commit

State

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

Diff stats

3 files+28 added−1 removed

  • tests:+21 added−0 removed
  • other:+7 added−1 removed

3 files+28 added−1 removed

modified:__tests__/__snapshots__/manual.js.snap+8 added
6 unmodified lines
7exports[`manual - es5 should check arguments 2`] = `"First argument to createDraft should be a plain object, an array, or an immerable object."`;89exports[`manual - es5 should check arguments 3`] = `"First argument to finishDraft should be an object from createDraft."`;1011exports[`manual - es5 should not finish drafts from produce 1`] = `"The draft provided was not created using \`createDraft\`"`;1213exports[`manual - es5 should not finish twice 1`] = `"The draft provided was has already been finished"`;1415exports[`manual - es5 should support patches drafts 1`] = `16Array [17 Array [18 Array [
38 unmodified lines
57exports[`manual - proxy should check arguments 2`] = `"First argument to createDraft should be a plain object, an array, or an immerable object."`;5859exports[`manual - proxy should check arguments 3`] = `"First argument to finishDraft should be an object from createDraft."`;6061exports[`manual - proxy should not finish drafts from produce 1`] = `"The draft provided was not created using \`createDraft\`"`;6263exports[`manual - proxy should not finish twice 1`] = `"The draft provided was has already been finished"`;6465exports[`manual - proxy should support patches drafts 1`] = `66Array [67 Array [68 Array [
33 unmodified lines
modified:__tests__/manual.js+13 added
modified:src/immer.js+7 added-1 removed
89 unmodified lines
90 if (!isDraftable(base)) throw new Error("First argument to createDraft should be a plain object, an array, or an immerable object.") // prettier-ignore91 const scope = ImmerScope.enter()92 const proxy = this.createProxy(base)93 scope.leave()94 proxy[DRAFT_STATE].customDraft = true95 return proxy96 }97 finishDraft(draft, patchListener) {98 if (!isDraft(draft)) throw new Error("First argument to finishDraft should be an object from createDraft.") // prettier-ignore98 const {scope} = draft[DRAFT_STATE]99 const state = draft[DRAFT_STATE]100 if (!state.customDraft) throw new Error("The draft provided was not created using `createDraft`") // prettier-ignore101 if (state.finalized) throw new Error("The draft provided was has already been finished") // prettier-ignore102 // TODO: check if created with createDraft103 // TODO: check if not finsihed twice104 const {scope} = state105 scope.usePatches(patchListener)106 return this.processResult(undefined, scope)107 }108 setAutoFreeze(value) {
173 unmodified lines