State sharing between islands #230
-
Hi there! What's the recommended way to share state between islands? One simple use-case (extending the base example) is if I'd like to have two |
Beta Was this translation helpful? Give feedback.
Replies: 11 comments 15 replies
-
This is a use-case I have had myself that I have not yet found a good solution for. I have some initial thoughts on how this could be resolved, but I am open to ideas! |
Beta Was this translation helpful? Give feedback.
-
have anyone tried something like that? :) |
Beta Was this translation helpful? Give feedback.
-
Personally, I went with a super-minimal state management lib (in my case: https://github.com/hmans/statery). It's as simple as using Can really recommend Statery. I've tried Zustand and Valtio but in the end Statery won for its simplicity. |
Beta Was this translation helpful? Give feedback.
-
stately is indeed nice, and is new to me -> will give it a go as Evt and
local/session storage work but only for islands to get values not
necessarily update other islands if values change.
I have been using EVT (works well for reading, storing state, but no way to
reactively get other islands to update short of a redirect),
To make islands fully reactive, so that any island can affect data in
another island or islands (and thus enable an island to re-actively update
state) I had resorted to setting up an event listener/dispatcher model.
I will play and test stately later, looks nice and clean and very Svelte
Store like.
…On Sun, Jul 31, 2022 at 11:14 AM Carlo Zottmann ***@***.***> wrote:
It's not *that* Deno-specific, Steven. But I agree it could help.
While we're at it, should the Fresh team ever consider packaging a state
management solution into the starter template, I vote for Statery
<https://github.com/hmans/statery>. It's to Zustand et all what Preact is
to React, after all. /㏄ @lucacasonato <https://github.com/lucacasonato>
—
Reply to this email directly, view it on GitHub
<#230 (reply in thread)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ATXWUNX4LJN6DVJTP63QM3DVWZGXDANCNFSM5YU77D7A>
.
You are receiving this because you are subscribed to this thread.Message
ID: ***@***.***>
|
Beta Was this translation helpful? Give feedback.
-
In Astro, which uses a similar island approach to Deno, they recommend Nanostores. I haven't tested in fresh myself, but I haven't seen anything that makes it look like it wouldn't work yet. |
Beta Was this translation helpful? Give feedback.
-
I'm building an event-bus library for exactly this use-case: It's currently badly documented, but one could already poke around in the code :) One particular thing I want to add is: I'm curious what you all think about this idea? |
Beta Was this translation helpful? Give feedback.
-
Preach just announced a general-purpose reactive library that neatly integrates with the rest of APIs. Seems like a very nice fit for Fresh |
Beta Was this translation helpful? Give feedback.
-
yeah, but to my defense I was in a rush :)
…On Sun, Jul 31, 2022 at 3:48 PM Carlo Zottmann ***@***.***> wrote:
Yeah, that's one of the issues I see w/ the window approach — the utter
lack of reactivity. It sounds like you then implemented a pubsub mechanism
to work around that lack ("setting up an event listener/dispatcher model").
That's basically re-inventing stores. ;)
I went down the same route in the past but binding components to the
"outside" (i.e. the window object) made the code harder to test; things
got unwieldy fast.
—
Reply to this email directly, view it on GitHub
<#230 (reply in thread)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ATXWUNT4PJBERV33IFUX5BDVW2G2DANCNFSM5YU77D7A>
.
You are receiving this because you commented.Message ID:
***@***.***>
|
Beta Was this translation helpful? Give feedback.
-
If there is no means of persisting application state without island-izing an entire Fresh app, does this not invalidate the architectural premise? Sidenote: significantly hinders use cases in which wallet extensions are used for authentication / secure message signing. Aka., Fresh doesn't like Web3 :/ as a major Deno fanatic and Fresh enthusiast, I'd very much like to see these pain points resolved. Is there no way to implicitly preserve state from contexts/signals? |
Beta Was this translation helpful? Give feedback.
-
I'm not sure if this will work for everything, but at first glance, this seems to work |
Beta Was this translation helpful? Give feedback.
-
Sharing state between islands is best done via signals. We have now a page in our docs that describes how to do that: https://fresh.deno.dev/docs/examples/sharing-state-between-islands |
Beta Was this translation helpful? Give feedback.
Sharing state between islands is best done via signals. We have now a page in our docs that describes how to do that: https://fresh.deno.dev/docs/examples/sharing-state-between-islands