Skip to content
Myr

Made ES5 version work

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 5036e7f · Browse files · 6 files+23 added−36 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+23 added−36 removed

  • tests:+0 added−25 removed
  • other:+23 added−11 removed

6 files+23 added−36 removed

deleted:__tests__/__snapshots__/current.js.snap-25 removed
1// Jest Snapshot v1, https://goo.gl/fbAQLP23exports[`auto freeze - es5 will freeze maps 1`] = `"[Immer] This object has been frozen and should not be mutated"`;45exports[`auto freeze - es5 will freeze maps 2`] = `"[Immer] This object has been frozen and should not be mutated"`;67exports[`auto freeze - es5 will freeze maps 3`] = `"[Immer] This object has been frozen and should not be mutated"`;89exports[`auto freeze - es5 will freeze sets 1`] = `"[Immer] This object has been frozen and should not be mutated"`;1011exports[`auto freeze - es5 will freeze sets 2`] = `"[Immer] This object has been frozen and should not be mutated"`;1213exports[`auto freeze - es5 will freeze sets 3`] = `"[Immer] This object has been frozen and should not be mutated"`;1415exports[`auto freeze - proxy will freeze maps 1`] = `"[Immer] This object has been frozen and should not be mutated"`;1617exports[`auto freeze - proxy will freeze maps 2`] = `"[Immer] This object has been frozen and should not be mutated"`;1819exports[`auto freeze - proxy will freeze maps 3`] = `"[Immer] This object has been frozen and should not be mutated"`;2021exports[`auto freeze - proxy will freeze sets 1`] = `"[Immer] This object has been frozen and should not be mutated"`;2223exports[`auto freeze - proxy will freeze sets 2`] = `"[Immer] This object has been frozen and should not be mutated"`;2425exports[`auto freeze - proxy will freeze sets 3`] = `"[Immer] This object has been frozen and should not be mutated"`;
modified:src/core/current.ts+6 added-1 removed
modified:src/core/finalize.ts+1 added-1 removed
131 unmodified lines
132 rootScope.canAutoFreeze_ = false133 } else return134 }135 // Search new objects for unfinalized drafts. Frozen objects should never contain drafts.136 if (isDraftable(childValue)) {136 if (isDraftable(childValue) && !Object.isFrozen(childValue)) {137 if (!rootScope.immer_.autoFreeze_ && rootScope.unfinalizedDrafts_ < 1) {138 // optimization: if an object is not a draft, and we don't have to139 // deepfreeze everything, and we are sure that no drafts are left in the remaining object140 // cause we saw and finalized all drafts already; we can stop visiting the rest of the tree.
16 unmodified lines
modified:src/plugins/es5.ts+8 added-1 removed
248 unmodified lines
249 // For all other cases, we don't have to compare, as they would have been picked up by the index setters250 return false251 }252253 function hasChanges_(state: ES5State) {254 return state.type_ === ProxyTypeES5Object255 ? hasObjectChanges(state)256 : hasArrayChanges(state)257 }258259 function assertUnrevoked(state: any /*ES5State | MapState | SetState*/) {260 if (state.revoked_) die(3, JSON.stringify(latest(state)))261 }262263 loadPlugin("ES5", {264 createES5Proxy_,259 willFinalizeES5_265 willFinalizeES5_,266 hasChanges_267 })268}
modified:src/utils/common.ts+7 added-8 removed
25 unmodified lines
26/*#__PURE__*/27export function isDraftable(value: any): boolean {28 if (!value) return false29 return (30 (isPlainObject(value) ||31 Array.isArray(value) ||32 !!value[DRAFTABLE] ||33 !!value.constructor[DRAFTABLE] ||34 isMap(value) ||35 isSet(value)) &&36 !isFrozen(value)30 isPlainObject(value) ||31 Array.isArray(value) ||32 !!value[DRAFTABLE] ||33 !!value.constructor[DRAFTABLE] ||34 isMap(value) ||35 isSet(value)36 )37}3839/*#__PURE__*/
130 unmodified lines
170 return Object.create(Object.getPrototypeOf(base), descriptors)171}172173export function freeze(obj: any, deep: boolean): void {175 if (isDraft(obj) || !isDraftable(obj)) return174 if (Object.isFrozen(obj) || isDraft(obj) || !isDraftable(obj)) return175 if (getArchtype(obj) > 1 /* Map or Set */) {176 obj.set = obj.add = obj.clear = obj.delete = dontMutateFrozenCollections as any177 }178 Object.freeze(obj)
12 unmodified lines
modified:src/utils/plugins.ts+1 added