-
-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Description
Describe the problem
svelte/reactivity is already exporting the Date, Set and Map classes which allow us to do things like this:
//+layout.ts - using adapter-static
import {SvelteDate} from "svelte/reactivity";
import type {LayoutLoad} from "./$types.js";
const time = new SvelteDate();
setInterval(()=>time.setTime(Date.now()), 1000);
export const load = (async ()=>{
return {
time
}) satisfies LayoutLoad;This example provides a single reactive reference to the current time to every page and sublayout that updates every second.
The same can be done with Sets, Maps and other reactive structures exported by svelte/reactivity.
Array, for an unknown reason, is not exported so we cannot do things like fetching data from the server, putting it in a reactive array and starting a WS or SSE subscription to append/remove items to/from said array when the server notifies us about an update.
I think having having such an asymmetric API is bad DX as it breaks developers expectations. From a developer POV it makes no sense that we can return a reactive Set/Map from a load function but not a reactive Array.
Describe the proposed solution
Export SvelteArray on svelte/reactivity so that adapter-static users can use it outside .svelte/.svelte.ts files like we can already use every other reactive class.
Importance
would make my life easier