added store with actions for actionsMenu

This commit is contained in:
Hanusiak Piotr 2022-01-25 13:42:41 +01:00
parent 69a2379e53
commit 67627637aa
4 changed files with 76 additions and 14 deletions

View file

@ -0,0 +1,36 @@
import { writable } from "svelte/store";
export interface ActionsMenuInterface {
displayName: string;
callback: Function;
}
function createActionsMenuStore() {
const actions = new Map<string, ActionsMenuInterface>();
const { subscribe, update, set } = writable<Map<string, ActionsMenuInterface>>(actions);
return {
subscribe,
addPossibleAction: (key: string, displayName: string, callback: Function) => {
update((actions) => {
actions.set(key, { displayName, callback });
return actions;
});
},
removePossibleAction: (key: string) => {
update((actions) => {
actions.delete(key);
return actions;
});
},
/**
* Hides menu
*/
clearActions: () => {
set(new Map<string, ActionsMenuInterface>());
}
};
}
export const actionsMenuStore = createActionsMenuStore();