small improvements
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 f8f402c · Browse files · 3 files·+11 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
3 files+11 added−9 removed
- other:+11 added−9 removed
Provenance
- Commit
7d0b7e8- Tree
c609ab0- Author
Michel Weststrate <mweststrate@gmail.com>- Committer
Michel Weststrate <mweststrate@gmail.com>- Parent
f8f402c
3 files changed+11 added−9 removed
modified:src/common.js+4 added
30 unmodified lines31323334353637383940414221 unmodified lines30 unmodified linesexport function setAutoFreeze(enableAutoFreeze) { autoFreeze = enableAutoFreeze}
export function shallowCopy(value) { return Array.isArray(value) ? value.slice() : Object.assign({}, value) // TODO: eliminate those isArray checks?}
export function finalizeNonProxiedObject(parent, finalizer) { // If finalize is called on an object that was not a proxy, it means that it is an object that was not there in the original // tree and it could contain proxies at arbitrarily places. Let's find and finalize them as well if (!isProxyable(parent)) return21 unmodified linesmodified:src/es5.js+4 added-5 removed
5 unmodified lines6 isProxyable,7 isProxy,8 freeze,9 PROXY_STATE,10- finalizeNonProxiedObject10+ finalizeNonProxiedObject,11+ shallowCopy12 } from "./common"13 14 const descriptors = {}15 let states = null29 unmodified lines45 assertUnfinished(state)46 if (!state.modified) {47 if (Object.is(source(state)[prop], value)) return48 markChanged(state)49+ prepareCopy(state)50 }49- prepareCopy(state)51 state.copy[prop] = value52 }53 54 function markChanged(state) {5 unmodified lines60 61 function prepareCopy(state) {62 if (state.hasCopy) return63 state.hasCopy = true63- state.copy = Array.isArray(state.base)64- ? state.base.slice()65- : Object.assign({}, state.base)64+ state.copy = shallowCopy(state.base)65 }66 67 // creates a proxy for plain objects / arrays68 function createProxy(parent, base) {164 unmodified linesmodified:src/proxy.js+3 added-4 removed
5 unmodified lines6 isProxyable,7 isProxy,8 freeze,9 PROXY_STATE,10- finalizeNonProxiedObject10+ finalizeNonProxiedObject,11+ shallowCopy12 } from "./common"13 14 let revocableProxies = null15 90 unmodified lines106 107 function markChanged(state) {108 if (!state.modified) {109 state.modified = true109- state.copy = Array.isArray(state.base)110- ? state.base.slice()111- : Object.assign({}, state.base) // TODO: eliminate those isArray checks?110+ state.copy = shallowCopy(state.base)111 Object.assign(state.copy, state.proxies) // yup that works for arrays as well112 if (state.parent) markChanged(state.parent)113 }114 }70 unmodified lines