platform/packages/presentation/src/context.ts
Andrey Sobolev 7621bccf22
UBER-1074: Svelte 4 (#4014)
Signed-off-by: Andrey Sobolev <haiodo@gmail.com>
2023-11-20 17:01:43 +07:00

24 lines
605 B
TypeScript

import { type ViewContext, type ViewContextType } from '@hcengineering/view'
import { writable } from 'svelte/store'
/**
* @public
*/
export class ContextStore {
constructor (readonly contexts: ViewContext[]) {}
getLastContext (): ViewContext | undefined {
return this.contexts[this.contexts.length - 1]
}
isIncludes (type: ViewContextType): boolean {
return (
this.contexts.find((it) => it.mode === type || (Array.isArray(it.mode) && it.mode.includes(type))) !== undefined
)
}
}
/**
* @public
*/
export const contextStore = writable<ContextStore>(new ContextStore([]))