-
Notifications
You must be signed in to change notification settings - Fork 11
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
Decouple base library from svelte #21
Comments
Yes, happy to switch. This was a fast experiment to get things rolling. Much happier to have a UI framework independent solution. Not sure how that looks inside the Svelte UI though. Looks like there's https://npm.io/package/svelte-mobx-observer and https://github.com/xelaok/svelte-mobx. Thoughts? |
Yes exactly, mobx is a bit like redux, but without the boilerplate with actions and so on. Then you have integrations with all major frameworks and tools, the ones you pointed out should work out of the box for svelte. I like it quite a bit, here is an example store that re-renders the components any time the state changes: https://github.com/holochain-open-dev/profiles/blob/main/ui/src/profiles.store.ts I think it makes for very simple but flexible state-management mechanism. |
Looks great to me! The Svelte store was definitely hard to wrap our heads around when hacking out syn, so I don't feel too fond of it to swap it out for something more extensible |
Svelte stores are actually very extensible & independent of svelte components. It may even be useful to extract The paradigm is different, being each store represents state that is used across the app. Each piece of data is isolated. With a consistent naming convention for each abstraction, an data flow framework can be made based solely on consistent domain terminology & systematized naming idioms (similar to the naming conventions of Holochain's I have used svelte stores for the past few years, & they can be used with other frameworks, in a similar way that RXjs can be used with multiple frameworks. You can create a functional reactive graph of data using the derived stores, use the One pattern that I have found to be useful is to lazily instantiate the stores. I use a Svelte also supports I would also be happy to refactor the codebase to utilize these patterns, which I have used in a number of apps over the past few years. I think it's somewhat novel but very powerful & will be a simpler solution to any of the other alternatives, as the incidental complexity of passing state around is largely removed. Also, each node in the functional reactive graph is it's own autonomous function (via lazy instantiation), so data flow logic is cleanly separated into distinct files. Another thing to consider, pnpm monorepos are a powerful way to separate libraries (npm packages) & apps in a single repository. A unifying paradigm, such as |
Mmm okey those are good points, don't know that much about svelte stores. What I would do is be very careful about the assumptions that are baked in the core syn library, not so much the svelte UI built on top of it. I wouldn't want for the core library to use context to share state around, because I want to be able to build reusable custom elements that don't need any additional setup to work (I'm doing all my stuff with Lit and would want to be able to include the core syn library). Have you used MobX, and if so, how does it compare to svelte stores? |
I evaluated MobX a couple of years ago. I don't doubt that it does everything you are saying it does. My stipulation is that Svelte Stores are capable of providing a good api which can be used in a general sense. Svelte Stores are simple observable container objects which can be decorated with additional functionality. Think of a Store as a spreadsheet "cell", which can other "cells" depend on it. An update to a "cell" will propagate to the other "cells". Since Svelte Stores are simple objects, just about any tried-and-true pattern of API development is on the table. IMO, the main difference between a Svelte Store & MobX Stores is how it's used. Svelte Stores are atomic "cells" holding one piece of mutable state while MobX Stores are "frames" holding a set of mutable state. Svelte Stores can be composed into a "frame" as well. Note that this analysis is on the idioms of both libraries. Right now, the Stores in Syn are Singletons. Stores do not need to be Singletons, though it's useful for the Store to already be instantiated so the dependent functions can observe the Stores, which is why I like to lazily instantiate Stores & other state on a The |
Mmm but what if I don't want to use the context pattern to build UIs on top of the core library? I mean, it's cool that we have some UIs that work that way, but we should be able to decouple the base business logic from that no? There are other ways to do dependency injection, and a lot of frameworks like angular or vue handle that in their own way. About svelte stores, I see... I would be inclined to use mobx either way, it feels more natural here because you don't want individual cells of state to be independent, you want the whole state to react to changes with business logic like you have inside the |
I'm quite over my head with this conversation |
@guillemcordoba If you don't want to use the context pattern, don't use it. Since svelte has @qubist No worries, I'll have some code soon. |
Word on the street is Zustand is The Way -- I'm using it in my latest project and it's great and simple. Also I hear it works well with a lot of processing such as in concert with threejs. |
I see the syn.js logic using svelte stores, which is fine for this UI, but won't be usable for other UIs built on top of this library and with any other framework.
I suggest using MobX, a js-only updatable and reactive store which has impressed me a lot, what do you think @zippy @qubist ? If you agree, I will gladly do the refactor, but only if you feel comfortable switching to that :)
The text was updated successfully, but these errors were encountered: