import { writable } from 'svelte/store'; function createVideosStore() { const { subscribe, set, update } = writable({videos: [], idx_videos: {}, loading: true}); return { subscribe, update: async (res_videos, cb=null) => { if (res_videos.status === 200) { const videos = await res_videos.json(); const idx_videos = {}; for (const v of videos) { idx_videos[v.id] = v; } update((t) => (Object.assign(t, {videos, idx_videos, loading: false}))); if (cb) { cb(videos); } } }, }; } export const videos = createVideosStore();