Skip to content
Myr

fix(es5): delete then set an existing property

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

Fixes #328

authored by Alec Larson · committed by Alec Larson · parent 5121d36 · Browse files · 1 file+16 added−5 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+16 added−5 removed

  • other:+16 added−5 removed

1 file+16 added−5 removed

modified:src/es5.js+16 added-5 removed
196 unmodified lines
197198function hasObjectChanges(state) {199 const {base, draft} = state200201 // Search for added keys. Start at the back, because non-numeric keys202 // are ordered by time of definition on the object.201 // Search for added keys and changed keys. Start at the back, because202 // non-numeric keys are ordered by time of definition on the object.203 const keys = Object.keys(draft)204 for (let i = keys.length - 1; i >= 0; i--) {205 const key = keys[i]206 const baseValue = base[key]207 // The `undefined` check is a fast path for pre-existing keys.206 if (base[keys[i]] === undefined && !has(base, keys[i])) {208 if (baseValue === undefined && !has(base, key)) {209 return true210 }211 // Once a base key is deleted, future changes go undetected, because its212 // descriptor is erased. This branch detects any missed changes.213 else {214 const value = draft[key]215 const state = value && value[DRAFT_STATE]216 if (state ? state.base !== baseValue : !is(value, baseValue)) {217 return true218 }219 }220 }221211 // Since no keys have been added, we can compare lengths to know if an212 // object has been deleted.222 // At this point, no keys were added or changed.223 // Compare key count to determine if keys were deleted.224 return keys.length !== Object.keys(base).length225}226227function hasArrayChanges(state) {
23 unmodified lines