Skip to content
Myr

refactor: "get" trap for Maps

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Alec Larson · committed by Alec Larson · parent eba300f · Browse files · 1 file+4 added−14 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+4 added−14 removed

  • other:+4 added−14 removed

1 file+4 added−14 removed

modified:src/proxy.js+4 added-14 removed
231 unmodified lines
232 const value = receiver.get(key)233 cb.call(thisArg, value, key, map)234 }),235 get: state => key => {236 const drafts = state[state.modified ? "copy" : "drafts"]236 if (!state.modified && state.drafts.has(key)) {237 return state.drafts.get(key)237 if (drafts.has(key)) {238 return drafts.get(key)239 }240240 if (state.modified && state.copy.has(key)) {241 return state.copy.get(key)242 }243241 const value = latest(state).get(key)245242 if (state.finalized || !isDraftable(value)) {243 return value244 }245246 const draft = createProxy(value, state)251252 if (!state.modified) {253 state.drafts.set(key, draft)247 drafts.set(key, draft)254 } else {255 state.copy.set(key, draft)256 }257248 return draft249 },250 keys: state => () => latest(state).keys(),251 values: iterateMapValues,
167 unmodified lines