on-change icon indicating copy to clipboard operation
on-change copied to clipboard

Path is empty for changes to class from own method

Open woubuc opened this issue 2 years ago • 1 comments

When changing a property on a class instance from within a method in that class, the callback is called with an empty path instead of the property that was changed.

import onChange from 'on-change';

class Foo {
  constructor() {
    this.bar = true;
  }

  toggle() {
    this.bar = !this.bar;
  }
}

let foo = onChange(
  new Foo(), 
  (path) => console.log(path), 
  { pathAsArray: true },
);


foo.toggle();
// Output: [] ❌
// Expected: ['bar']


foo.bar = !foo.bar;
// Output: ['bar'] ✔️

woubuc avatar Jul 27 '22 17:07 woubuc

Ever find a workaround for this? Thanks!

dtcooper avatar Aug 06 '23 14:08 dtcooper