Skip to content
Myr

refactor: markChanged function

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 930b4ab · Browse files · 1 file+17 added−15 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+17 added−15 removed

  • other:+17 added−15 removed

1 file+17 added−15 removed

modified:src/proxy.js+17 added-15 removed
359 unmodified lines
360 return desc && desc.value361}362363function markChanged(state) {364 let resetDrafts = true365 let assignFn = assign366 if (isMap(state.base)) {367 assignFn = assignMap368 } else if (isSet(state.base)) {369 assignFn = assignSet370 // We need to keep track of how non-proxied objects are related to proxied ones.371 // For other data structures that support keys we can use those keys to access the item, notwithstanding it being a proxy or not.372 // Sets, however, do not have keys.373 // We use original objects as keys and keep proxified values as values.374 resetDrafts = false375 }364 if (!state.modified) {365 state.modified = true378 state.copy = assignFn(shallowCopy(state.base), state.drafts)379 if (resetDrafts) {366367 const {base, drafts, parent} = state368 const copy = shallowCopy(base)369370 if (isSet(base)) {371 // Note: The `drafts` property is preserved for Set objects, since372 // we need to keep track of which values are drafted.373 assignSet(copy, drafts)374 } else {375 // Merge nested drafts into the copy.376 if (isMap(base)) assignMap(copy, drafts)377 else assign(copy, drafts)378 state.drafts = null379 }382 if (state.parent) markChanged(state.parent)380381 state.copy = copy382 if (parent) {383 markChanged(parent)384 }385 }386}387388function makeIterable(next) {
46 unmodified lines