This repository has been archived on 2024-03-04. You can view files and clone it, but cannot push or open issues or pull requests.
maatma-videos/src/stores/videos.js

28 lines
631 B
JavaScript

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();