mfellner / valtio-factory

Create and compose valtio state using the factory pattern.
https://codesandbox.io/s/valtio-factory-example-j7v2s
MIT License
40 stars 2 forks source link

Unable to chain factory.onCreate #1

Closed hellowodl closed 2 years ago

hellowodl commented 2 years ago

In order to clean up my subscriptions in a way that's as clean as possible, I'd like to be able to chain factory.onCreate.

Currently this is impossible to do. The factory.onCreate will always be the only function that gets called in the stack.

mfellner commented 2 years ago

Thanks for the issue!

Chaining onCreate currently doesn’t work as expected and leads to previously added callbacks being replaced.

This is because the factory stores only a single callback instead of an array.

Should be pretty easy to implement. Feel free to send a PR, or I’ll try to get it done when I have some time.