Skip to content

Commit

Permalink
Merge fb5c316 into fb0f3a0
Browse files Browse the repository at this point in the history
  • Loading branch information
ryuever committed Feb 4, 2020
2 parents fb0f3a0 + fb5c316 commit b5a9c67
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
15 changes: 15 additions & 0 deletions __tests__/patch.js
Expand Up @@ -648,6 +648,21 @@ describe("arrays - splice (shrink)", () => {
)
})

describe.only("arrays - delete", () => {
runPatchTest(
{
x: [
{a: 1, b: 2},
{c: 3, d: 4}
]
},
d => {
delete d.x[1].c
},
[{op: "remove", path: ["x", 1, "c"]}]
)
})

describe("sets - add - 1", () => {
runPatchTest(
new Set([1]),
Expand Down
15 changes: 11 additions & 4 deletions src/es5.ts
Expand Up @@ -241,15 +241,22 @@ function markChangesRecursively(object: any) {
markChangedES5(state)
}
})
} else if (type === ProxyType.ES5Array && hasArrayChanges(state)) {
markChangedES5(state)
assigned.length = true
} else if (type === ProxyType.ES5Array) {
if (hasArrayChanges(state)) {
markChangedES5(state)
assigned.length = true
}

if (draft.length < base.length) {
for (let i = draft.length; i < base.length; i++) assigned[i] = false
} else {
for (let i = base.length; i < draft.length; i++) assigned[i] = true
}
for (let i = 0; i < draft.length; i++) {

// Minimum count is enough, the other parts has been processed.
const min = Math.min(draft.length, base.length)

for (let i = 0; i < min; i++) {
// Only untouched indices trigger recursion.
if (assigned[i] === undefined) markChangesRecursively(draft[i])
}
Expand Down

0 comments on commit b5a9c67

Please sign in to comment.