Skip to content
Myr

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

3 files+11 added−9 removed

modified:src/common.js+4 added
modified:src/es5.js+4 added-5 removed
5 unmodified lines
6 isProxyable,7 isProxy,8 freeze,9 PROXY_STATE,10 finalizeNonProxiedObject10 finalizeNonProxiedObject,11 shallowCopy12} from "./common"1314const descriptors = {}15let states = null
29 unmodified lines
45 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}5354function markChanged(state) {
5 unmodified lines
6061function 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}6667// creates a proxy for plain objects / arrays68function createProxy(parent, base) {
164 unmodified lines
modified:src/proxy.js+3 added-4 removed
5 unmodified lines
6 isProxyable,7 isProxy,8 freeze,9 PROXY_STATE,10 finalizeNonProxiedObject10 finalizeNonProxiedObject,11 shallowCopy12} from "./common"1314let revocableProxies = null15
90 unmodified lines
106107function 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