@humanspeak/svelte-subscribe
Version:
Subscribe to non top-level stores in your Svelte templates
10 lines (9 loc) • 375 B
JavaScript
import { derived } from 'svelte/store';
export const derivedKeys = (storeMap) => {
// Freeze the order of entries.
const entries = Object.entries(storeMap);
const keys = entries.map(([key]) => key);
return derived(entries.map(([, store]) => store), ($stores) => {
return Object.fromEntries($stores.map((store, idx) => [keys[idx], store]));
});
};