Skip to content

Export SvelteArray on svelte/reactivity #14637

@kran6a

Description

@kran6a

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions