Skip to content

getters/setters are executed against the original model, not the modified one #161

@azhiv

Description

@azhiv

Consider the following class:

class A {
  foo = 1;

  get bar(): number {
    return 2 * this.foo;
  }

  set bar(value: number) {
    this.foo = value / 2;
  }
}

If you create a change buffer over an instance of this class and modify it:

changebuffer.set('foo', 2);
console.log(changebuffer.get('bar'));      // 2, but I'd expect 4

changebuffer.set('bar', 6);
console.log(changebuffer.get('foo'));      // 1, but I'd expect 3

the results are a bit unexpected. Would you consider getting the property descriptor

const descriptor = Object.getOwnPropertyDescriptor(Object.getPrototypeOf(target), prop);

and then executing it against the change buffer instance?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions