Skip to content
Myr

Make the markChangedProxy skip the getter without a setter

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

authored by dalcib · committed by dalcib · parent 949960f · Browse files · 2 files+48 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

2 files+48 added−2 removed

  • tests:+40 added−0 removed
  • other:+8 added−2 removed

2 files+48 added−2 removed

modified:__tests__/base.js+40 added
2088 unmodified lines
2089 expect(result[0]).toBe(random)2090 })2091 })2092 }20932094 describe("class with getters", () => {2095 class State {2096 [immerable] = true2097 _bar = {baz: 1}2098 foo2099 get bar() {2100 return this._bar2101 }2102 syncFoo() {2103 this.foo = this.bar.baz2104 }2105 }2106 const state = new State()21072108 it("should use a method to assing a field using a getter that return a non primitive object", () => {2109 const newState = produce(state, draft => {2110 draft.syncFoo()2111 })2112 expect(newState.foo).toEqual(1)2113 })2114 })21152116 describe("class with setters", () => {2117 class State {2118 [immerable] = true2119 _bar = 02120 set bar(x) {2121 this._bar = x2122 }2123 }2124 const state = new State()21252126 it("should define a field with a setter", () => {2127 const newState3 = produce(state, d => {2128 d.bar = 12129 })2130 expect(newState3._bar).toEqual(1)2131 })2132 })2133}21342135function testLiteralTypes(produce) {2136 class Foo {}
66 unmodified lines
modified:src/core/proxy.ts+8 added-2 removed
237 unmodified lines
238 state.type_ === ProxyTypeProxyArray239 ) {240 const copy = (state.copy_ = shallowCopy(state.base_))241 each(state.drafts_!, (key, value) => {242 const descProto = Object.getOwnPropertyDescriptor(243 Object.getPrototypeOf(copy),244 key245 )246 if (!(descProto && descProto.get && !descProto.set)) {242 // @ts-ignore243 copy[key] = value247 // @ts-ignore248 copy[key] = value249 }250 })251 state.drafts_ = undefined252 }253
11 unmodified lines