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

Question about the usage on details:true and lists #108

Open
remyguillaume opened this issue Jul 2, 2024 · 0 comments
Open

Question about the usage on details:true and lists #108

remyguillaume opened this issue Jul 2, 2024 · 0 comments

Comments

@remyguillaume
Copy link
Contributor

Hello,

I am using on-change to watch changes in the state of my application.

Until now, I was using the default configuration. With this, when I listen to a change in my list, if I add a new element in my list, the path I get in the onChange method if the array itself.
For example:

this.proxy = onChange(
      this.state,
      (path, value, oldValue, _applyData) => {
        /* Do something */

      },
      {
        ignoreUnderscores: true,
        ignoreSymbols: true,
      });

And when I do this.state.selectedFeatures.push(...features), then the path in the onChange method is selectedFeatures.

Now, I add some problems with some functions like forEach(), which were not triggering all the events, but only one event at the end of the loop. So I've tried to activated the details:true options, as documented. This worked well, except that now the path has changed when I add elements in my list.

For example, now I have:

this.proxy = onChange(
      this.state,
      (path, value, oldValue, _applyData) => {
        /* Do something */

      },
      {
        ignoreUnderscores: true,
        ignoreSymbols: true,
        details: true
      });

And when I do this.state.selectedFeatures.push(...features), then the path in the onChange method is now selectedFeatures.0.

I don't really understand the philosophy here. Is it intentional? Is it a bug?
(I could perhaps try to sove it by myself in a Pull-Request, but I would be happy to discuss this before.)
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

1 participant