Skip to content

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

@woubuc

Description

@woubuc

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'] ✔️

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions