Skip to content
Myr

Fixed bug where new objects where proxied

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 94ae587 · Browse files · 3 files+22 added−24 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+22 added−24 removed

  • other:+22 added−24 removed

3 files+22 added−24 removed

modified:src/common.js+10 added-19 removed
modified:src/es5.js+6 added-2 removed
35 unmodified lines
3637function get(state, prop) {38 assertUnfinished(state)39 const value = source(state)[prop]40 if (!state.finalizing && !isProxy(value) && isProxyable(value)) {40 if (!state.finalizing && value === state.base[prop] && isProxyable(value)) {41 // only create a proxy if the value is proxyable, and the value was in the base state42 // if it wasn't in the base state, the object is already modified and we will process it in finalize43 prepareCopy(state)44 return (state.copy[prop] = createProxy(state, value))45 }46 return value
107 unmodified lines
154 })155 return freeze(res)156}157158// TODO: unduplicate159export function finalizeArray(proxy, state) {160 const res = (state.copy = shallowCopy(proxy))161 const base = state.base162 each(res, (i, value) => {159 res[i] = finalize(value)163 if (value !== base[i]) res[i] = finalize(value)164 })165 return freeze(res)166}167
58 unmodified lines
modified:src/proxy.js+6 added-3 removed
8 unmodified lines
9 PROXY_STATE,10 finalize,11 shallowCopy,12 verifyReturnValue,13 each13 each,14 finalizeNonProxiedObject15} from "./common"1617let proxies = null18
40 unmodified lines
59function get(state, prop) {60 if (prop === PROXY_STATE) return state61 if (state.modified) {62 const value = state.copy[prop]62 if (!isProxy(value) && isProxyable(value))63 if (value === state.base[prop] && isProxyable(value))64 // only create proxy if it is not yet a proxy, and not a new object65 // (new objects don't need proxying, they will be processed in finalize anyway)66 return (state.copy[prop] = createProxy(state, value))67 return value68 } else {69 if (prop in state.proxies) return state.proxies[prop]
70 unmodified lines
140141export function finalizeArray(state) {142 const copy = state.copy143 each(copy, (i, value) => {141 copy[i] = finalize(value)144 if (state.base[i] !== value) copy[i] = finalize(value)145 })146 return freeze(copy)147}148
17 unmodified lines