Skip to content

Using rxjs with zustand ? #285

Closed Answered by patdx
GZLiew asked this question in General
Jan 26, 2021 · 3 comments · 7 replies
Discussion options

You must be logged in to vote

Here's an attempt to implement a toStream function similar to mobx-utils that can take a store, selector and output a RxJS observable.

I'm not sure how to "correctly" infer the State shape given only the StoreApi interface, especially since various middleware like subscribeWithSelector override the subscribe() function and the subscribe function itself seems to have multiple signatures too. My attempt is shown at type InferState, but maybe the preferred way to do this in Zustand is to provide a middleware that exposes a new function on the StoreApi?

Note: Only very roughly tested with zustand/vanilla.

Please feel free to modify/use without attribution in any way you like.

// zustand-utils.ts

Replies: 3 comments 7 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
7 replies
@patdx
Comment options

@patdx
Comment options

@dai-shi
Comment options

@GZLiew
Comment options

@patdx
Comment options

Answer selected by GZLiew
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
5 participants