Closed wainwrightmark closed 1 year ago
Great idea! Feel free to open a PR
Am working on implementing this. However I've run into a bit of a problem - the code I posted above doesn't work - it seems like you can only have one listener for each Store
- in the book it says
NOTE: Successive calls to init_listener on the same type will replace the existing listener with the new one.
but I took that to mean that you can't register the same listener twice - not that you can only have one type of listener for each Store
. Is that intended? It seems like it would be nice to have more than one (that's the whole point of this issue :) )
If it's not intended or you want it changed I can have a go but that's a slightly bigger job and might be a breaking change...
Are you getting an error? You should definitely be able to have multiple types of listeners for one store
No error. It's just the first listener is dropped when the second listener is registered. Try out this example: https://github.com/wainwrightmark/yewdux/tree/multiple-listeners/examples/multiple_listeners
I believe it should be relatively easy to fix - just make ListenerStore
generic over the type of listener rather than the type of store.
That's definitely a bug! Yes you're correct, that would fix it. Feel free to include it in your PR, and maybe a unit test too?
Hi. I love this crate - I use it in all my yew projects.
At the moment it's a bit of a pain to use listeners because I am almost always using the Derive attribute to implement
Store
and persist to local storage. If I want to add a listener to a Store with zero listeners I need to expand the macro and add theinit_listener
statements. This is a bit ugly and potentially error prone. It would be nice to have an attribute to initialize extra listeners in the generated code.For example you could write something like:
Instead of:
Happy to have a go and do a PR if you think this is a good idea.