Skip to content
Myr

Fixed finalizing array

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

authored by iruca3 · committed by iruca3 · parent 7290670 · Browse files · 3 files+44 added−2 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+44 added−2 removed

  • tests:+34 added−0 removed
  • other:+10 added−2 removed

3 files+44 added−2 removed

modified:__tests__/base.js+34 added
504 unmodified lines
505 room: {elephant: {kiddo: {age: 10, legs: 5}}}506 })507 })508509 it("should not throw error", () => {510 const base = {511 arr: [512 {513 id: "100",514 arr: [{id: "1", no: 1}, {id: "2", no: 2}]515 },516 {id: "3", no: 3}517 ]518 }519 const result = produce(base, draft => {520 const base = draft.arr[0]521 draft.arr = draft.arr.slice(0, 1)522 const newArr = {523 id: "101",524 arr: [base, {id: "3"}]525 }526 draft.arr.splice(0, 1, newArr)527 draft.arr[0].arr[1].no = 3528 })529 expect(result).toEqual({530 arr: [{531 id: "101",532 arr: [533 {534 id: "100",535 arr: [{id: "1", no: 1}, {id: "2", no: 2}]536 },537 {id: "3", no: 3}538 ]539 }]540 })541 })542543 it("should handle dates correctly", () => {544 const data = {date: new Date()}545 const next = produce(data, draft => {546 draft.x = true
176 unmodified lines
modified:src/es5.js+5 added-1 removed
154 unmodified lines
155export function finalizeArray(proxy, state) {156 const res = (state.copy = shallowCopy(proxy))157 const base = state.base158 each(res, (i, value) => {159 if (value !== base[i]) res[i] = finalize(value)159 if (value !== base[i]) {160 res[i] = finalize(value)161 } else {162 res[i] = finalize(res[i])163 }164 })165 return freeze(res)166}167
58 unmodified lines
modified:src/proxy.js+5 added-1 removed