More code dedupping
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 ee544cc · Browse files · 3 files·+14 added−27 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+14 added−27 removed
- other:+14 added−27 removed
Provenance
- Commit
29262e3- Tree
e8e7609- Author
Michel Weststrate <mweststrate@gmail.com>- Committer
Michel Weststrate <mweststrate@gmail.com>- Parent
ee544cc
3 files changed+14 added−27 removed
modified:src/common.js+13 added-7 removed
123123458 unmodified lines63646566707172676869707172737475767778798081828384858681878889909125 unmodified linesimport {finalizeObject as finalizeObjectProxy} from "./proxy"import {finalizeObject as finalizeObjectEs5} from "./es5"
export const PROXY_STATE = typeof Symbol !== "undefined" ? Symbol("immer-proxy-state") : "__$immer_state"58 unmodified lines const state = base[PROXY_STATE] if (state.modified === true) { if (state.finalized === true) return state.copy state.finalized = true return useProxies ? finalizeObjectProxy(state) : finalizeObjectEs5(base, state) return finalizeObject( useProxies ? state.copy : (state.copy = shallowCopy(base)), state ) } else { return state.base } } finalizeNonProxiedObject(base) return base}
function finalizeObject(copy, state) { const base = state.base each(copy, (prop, value) => { if (value !== base[prop]) copy[prop] = finalize(value) }) return freeze(copy)}
export function finalizeNonProxiedObject(parent) {function finalizeNonProxiedObject(parent) { // 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)) return if (Object.isFrozen(parent)) return25 unmodified linesmodified:src/es5.js-9 removed
129 unmodified lines130 function hasArrayChanges(state) {131 return state.proxy.length !== state.base.length132 }133 134-export function finalizeObject(proxy, state) {135- const res = (state.copy = shallowCopy(proxy))136- const base = state.base137- each(res, (prop, value) => {138- if (value !== base[prop]) res[prop] = finalize(value)139- })140- return freeze(res)141-}142-134 export function produceEs5(baseState, producer) {135 const prevStates = states136 states = []137 try {54 unmodified linesmodified:src/proxy.js+1 added-11 removed
8 unmodified lines9 PROXY_STATE,10 finalize,11 shallowCopy,12 verifyReturnValue,13- each,14- finalizeNonProxiedObject13+ each14 } from "./common"15 16 let proxies = null17 109 unmodified lines127 proxies.push(proxy)128 return proxy.proxy129 }130 132-export function finalizeObject(state) {133- const copy = state.copy134- const base = state.base135- each(copy, (prop, value) => {136- if (value !== base[prop]) copy[prop] = finalize(value)137- })138- return freeze(copy)139-}140-131 export function produceProxy(baseState, producer) {132 const previousProxies = proxies133 proxies = []134 try {13 unmodified lines