I also like svelte quite a lot although I was/am genuinely a bit confused as to how to join svelte to some external [state machine / business logic]. I ended up with runes basically infecting the entire codebase, but presumably a proper boundary must be possible?
For complex things, I came up with a pattern that stores the state externally from the components in a single centralized file. So the components just become simple shells that render the state and forward events. (All the complex business logic can be tested without the DOM/headless browser.)
I call it "nation state" because it groups sets of related variables together in a scope between local and global.
I implemented the pattern with Svelte runes, but I think it could be implemented with anything; even React.
I went into more detail here (with live example/code): https://www.reddit.com/r/sveltejs/comments/1dgf8la/comment/l...
Yes this is the way to do it, global-ish state files with getters and setters. I’ll have a .svelte.ts file (or a few of them) with a typed state object, maybe a function for refreshing it or syncing it with a backend api, import the state all over the place.
Might be an anti pattern but it works really well.
I think I follow but IIRC my problem was something like that the getters and setters had to be quite "flat". if they weren't they would recursively infect everything top-down and then not work anyway because of boundaries in the deep reactivity.
> runes basically infecting the entire codebase
Yeah sadly the stores the author talks about here aren't the right way to do things anymore in modern svelte and they're all-in on Runes.
Stores were a big part of the reason I liked svelte; they were so conceptually simple, extensible with plain JS, and made interop outside of Svelte trivial without the Svelte magic leaking out.
They're still in Svelte, but they mix poorly with runes and are basically unsupported in runes mode. I opened up a bug about store behavior not working like it used to when mixing with runes, and the response was pretty much "yeah we don't expect it to work like that anymore when runes mode is enabled".
I don't even mind the runes I just don't get the impression from the docs that anyone has a clear feeling about how to actually use them e.g. forget the toy examples, suppose an alien has given me clump of minified business logic and we have to make it work.
Yeah, I try build an dashboard admin that has complex state passing into each other
and its not elegant, lets call it that way