2020-11-17 13:08:24 +01:00
|
|
|
import { writable, derived } from "svelte/store"
|
|
|
|
import { routeStore } from "./routes"
|
2020-11-13 16:42:32 +01:00
|
|
|
|
|
|
|
export const createScreenStore = () => {
|
2020-11-17 13:08:24 +01:00
|
|
|
console.log("CREATE SCREEN STORE")
|
|
|
|
|
|
|
|
const screens = writable([])
|
|
|
|
const store = derived([screens, routeStore], ([$screens, $routeStore]) => {
|
|
|
|
const activeScreen = $screens.find(
|
|
|
|
screen => screen.route === $routeStore.activeRoute
|
|
|
|
)
|
|
|
|
return {
|
|
|
|
screens: $screens,
|
|
|
|
activeScreen,
|
|
|
|
}
|
2020-11-13 16:42:32 +01:00
|
|
|
})
|
|
|
|
|
|
|
|
const fetchScreens = () => {
|
|
|
|
const frontendDefinition = window["##BUDIBASE_FRONTEND_DEFINITION##"]
|
2020-11-17 13:08:24 +01:00
|
|
|
screens.set(frontendDefinition.screens)
|
2020-11-13 16:42:32 +01:00
|
|
|
}
|
2020-11-17 13:08:24 +01:00
|
|
|
|
|
|
|
return {
|
|
|
|
subscribe: store.subscribe,
|
|
|
|
actions: { fetchScreens },
|
2020-11-13 16:42:32 +01:00
|
|
|
}
|
2020-11-17 13:08:24 +01:00
|
|
|
}
|
2020-11-13 16:42:32 +01:00
|
|
|
|
2020-11-17 13:08:24 +01:00
|
|
|
if (!window.bbSDKScreenStore) {
|
|
|
|
window.bbSDKScreenStore = createScreenStore()
|
2020-11-13 16:42:32 +01:00
|
|
|
}
|
2020-11-17 13:08:24 +01:00
|
|
|
|
|
|
|
export const screenStore = window.bbSDKScreenStore
|