Skip to content
Myr

Removed some duplicate code

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 4ad622f · Browse files · 3 files+6 added−49 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+6 added−49 removed

  • other:+6 added−49 removed

3 files+6 added−49 removed

modified:src/common.js+2 added-12 removed
modified:src/es5.js+4 added-29 removed
69 unmodified lines
70}7172// creates a proxy for plain objects / arrays73function createProxy(parent, base) {74 const proxy = Array.isArray(base)75 ? createArrayProxy(base)76 : createObjectProxy(base)74 const proxy = shallowCopy(base)75 each(base, i => {76 Object.defineProperty(proxy, "" + i, createPropertyProxy("" + i))77 })78 const state = createState(parent, proxy, base)79 createHiddenProperty(proxy, PROXY_STATE, state)80 states.push(state)81 return proxy
14 unmodified lines
96 })97 )98}9999function createObjectProxy(base) {100 const proxy = Object.assign({}, base)101 each(base, prop => {102 Object.defineProperty(proxy, prop, createPropertyProxy(prop))103 })104 return proxy105}106107function createArrayProxy(base) {108 const proxy = new Array(base.length)109 each(base, i => {110 Object.defineProperty(proxy, "" + i, createPropertyProxy("" + i))111 })112 return proxy113}114100function assertUnfinished(state) {101 if (state.finished === true)102 throw new Error(103 "Cannot use a proxy that has been revoked. Did you pass an object from inside an immer function to an async process?"
35 unmodified lines
139 })140 return freeze(res)141}142158// TODO: unduplicate159export function finalizeArray(proxy, state) {160 const res = (state.copy = shallowCopy(proxy))161 const base = state.base162 each(res, (i, value) => {163 if (value !== base[i]) res[i] = finalize(value)164 })165 return freeze(res)166}167143export function produceEs5(baseState, producer) {144 const prevStates = states145 states = []146 try {
54 unmodified lines
modified:src/proxy.js-8 removed
136 unmodified lines
137 })138 return freeze(copy)139}140141export function finalizeArray(state) {142 const copy = state.copy143 each(copy, (i, value) => {144 if (state.base[i] !== value) copy[i] = finalize(value)145 })146 return freeze(copy)147}148141export function produceProxy(baseState, producer) {142 const previousProxies = proxies143 proxies = []144 try {
13 unmodified lines