38 lines
690 B
JavaScript
38 lines
690 B
JavaScript
import { writable, derived } from "svelte/store"
|
|
|
|
export const createSidePanelStore = () => {
|
|
const initialState = {
|
|
contentId: null,
|
|
}
|
|
const store = writable(initialState)
|
|
const derivedStore = derived(store, $store => {
|
|
return {
|
|
...$store,
|
|
open: $store.contentId != null,
|
|
}
|
|
})
|
|
|
|
const open = id => {
|
|
store.update(state => {
|
|
state.contentId = id
|
|
return state
|
|
})
|
|
}
|
|
const close = () => {
|
|
store.update(state => {
|
|
state.contentId = null
|
|
return state
|
|
})
|
|
}
|
|
|
|
return {
|
|
subscribe: derivedStore.subscribe,
|
|
actions: {
|
|
open,
|
|
close,
|
|
},
|
|
}
|
|
}
|
|
|
|
export const sidePanelStore = createSidePanelStore()
|