import { derived, writable } from 'svelte/store'; import type { Readable, Writable } from 'svelte/store'; export type Actions = { topic?: TopicAction; }; export type TopicAction = { id: string; }; /* * This is a store to set the actions in the top header. */ const actions: Writable = writable({}); export const enableTopicActions = (id: string) => { actions.update((actionsValue: Actions): Actions => { actionsValue.topic = { id }; return actionsValue; }); }; export const disableTopicActions = () => { actions.update((actionsValue): Actions => { delete actionsValue.topic; return actionsValue; }); }; export const topicActions: Readable = derived(actions, ($actions) => $actions.topic);