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

Subscriptions are fired multiple times #118

Closed
tilman-tomorrow opened this issue Aug 25, 2020 · 2 comments
Closed

Subscriptions are fired multiple times #118

tilman-tomorrow opened this issue Aug 25, 2020 · 2 comments

Comments

@tilman-tomorrow
Copy link

I love undux and how easy it is to use! Thanks for creating it and maintaining it!
I just stumbled across an behavior that I felt a bit weird to me: When I subscribe to a store change via store.on('foo').subscribe(a => ...), the effect is fired not once, but lots of times: On the first change it fires once, on the second twice, on the third three times and so on. Is this intended?

Actual behavior
After a couple of store changes, each effect is fired up to hundreds of times (for 40 store changes the effects were fired 820 times)

Expected behavior
Each change should only fire an effect only once

Steps to reproduce
Here's an example: https://codesandbox.io/s/undux-demo-forked-tmb1o?file=/src/index.js:488-563 (watch the console.log)

@DeanKamali
Copy link

DeanKamali commented Aug 26, 2020

Temporary fix/workaround, you could try debounce function

@tilman-tomorrow
Copy link
Author

Thanks for the hint @DeanKamali! I tried around with it, and realized that I was using the effects inside a React Component which looked it was reloaded every time the store changed.
Now I switched to using effects via export default createConnectedStore(initialState, withEffects); (https://undux.org/#quick-start/2), which I didn't see before. That works fine!

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