Solidjs and RxJS compatibility

Introduction: Hi! I’m new to Solidjs and I like that idea where it’s similar to React and does not re-render the entire component for no obvious reason. I came from Angular and React. Since Solidjs does not re-render or re-executes the entire function/component, it’s so easy to use setTimeout/setInterval inside it. Should RxJS also now be highly compatible with Solid? And the idea that we can use onCleanup() to unsubscribe to observables or any other subscriptions.
9 Replies
Alex Lohr
Alex Lohr16mo ago
Welcome to our discord, John! While we do have tools like from and observable that allow a seamless integration of RxJS, Solid's reactivity is sufficient for most cases. The problem with RxJS is that it is truly excellent when it comes to mapping complexity into code, thus it becomes easier to write complex code than to reduce complexity. However, the former approach makes applications less maintainable. So we try to restrict our use of RxJS to those cases when complexity cannot be avoided.
lightzane
lightzane16mo ago
Thank you Alex! For example I want to have a global state that can be accessed by all components. In Angular, I use BehaviorSubject from RxJS.
What will be the equivalent for Solid in this scenario?
I can only see the Context can be used as an approach, but it seems when I have multiple context, it could lead to multiple nested context tags.. e.g.
<OneProvider>
<TwoProvider>
<ThreeProvider>
<App />
</ThreeProvider>
</TwoProvider>
</OneProvider>
<OneProvider>
<TwoProvider>
<ThreeProvider>
<App />
</ThreeProvider>
</TwoProvider>
</OneProvider>
And if I try to implement a global context, it seems that it may bloat the file and mixed all the states where we could group them. Or am I missing something for sure. I’m still exploring…
Alex Lohr
Alex Lohr16mo ago
Solid's state is not necessarily bound to context. You can define a global store. Only effects need to run inside a reactive root, but you can create such with createRoot.
Alex Lohr
Alex Lohr16mo ago
GitHub
solid-primitives/packages/context at main · solidjs-community/solid...
A library of high-quality primitives that extend SolidJS reactivity. - solid-primitives/packages/context at main · solidjs-community/solid-primitives
Alex Lohr
Alex Lohr16mo ago
This is a community primitive created for that use case.
lightzane
lightzane16mo ago
Oh I think this is what I’m trying to look for. Finally, quickly found it with your help. You’re a life saver! Just one last clarification, based on screenshot below (which I saw from the github link provided), this is just meant as static structure, but the states internal in these contexts is dynamic and can still change its values. Like example multiple context has its own createSignal or createStore. Is my understanding correct?
Alex Lohr
Alex Lohr16mo ago
Yes, it is. As long as the signal is defined, there will be no problem. There's only a problem if you tried to use this to dynamically enable and disable providers.
lightzane
lightzane16mo ago
Alright. Thanks for helping me find this documentation!
Alex Lohr
Alex Lohr16mo ago
Happy to help.
Want results from more Discord servers?
Add your server