Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Path is empty for changes to class from own method #98

Open
woubuc opened this issue Jul 27, 2022 · 1 comment
Open

Path is empty for changes to class from own method #98

woubuc opened this issue Jul 27, 2022 · 1 comment

Comments

@woubuc
Copy link

woubuc commented Jul 27, 2022

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'] ✔️
@dtcooper
Copy link

dtcooper commented Aug 6, 2023

Ever find a workaround for this? Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants