I am trying to follow Redux style patterns in my SvelteKit app. I want to the attach logging middleware to my state management.
I understand that store.subscribe
has been replaced with $effect
rune, however something like:
$effect(() => console.log(myStore))
Would not work since $effect
can only be used inside an effect (e.g. during component initialisation).
How can I implement this kind of logging in SvelteKit? Are there any established patterns or mechanisms for achieving this?
I am trying to follow Redux style patterns in my SvelteKit app. I want to the attach logging middleware to my state management.
I understand that store.subscribe
has been replaced with $effect
rune, however something like:
$effect(() => console.log(myStore))
Would not work since $effect
can only be used inside an effect (e.g. during component initialisation).
How can I implement this kind of logging in SvelteKit? Are there any established patterns or mechanisms for achieving this?
Share Improve this question edited Feb 15 at 18:45 Paolo 21.1k21 gold badges76 silver badges121 bronze badges asked Feb 15 at 4:45 Justin LeeJustin Lee 111 Answer
Reset to default 1You can create independent effects by wrapping the $effect
in an $effect.root
.
(These also need to be cleaned up manually.)