2020-11-18 01:08:24 +13:00
|
|
|
import { writable, derived } from "svelte/store"
|
|
|
|
import { routeStore } from "./routes"
|
2020-11-14 04:42:32 +13:00
|
|
|
|
|
|
|
export const createScreenStore = () => {
|
2020-11-18 01:08:24 +13: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-14 04:42:32 +13:00
|
|
|
})
|
|
|
|
|
|
|
|
const fetchScreens = () => {
|
|
|
|
const frontendDefinition = window["##BUDIBASE_FRONTEND_DEFINITION##"]
|
2020-11-18 01:08:24 +13:00
|
|
|
screens.set(frontendDefinition.screens)
|
2020-11-14 04:42:32 +13:00
|
|
|
}
|
2020-11-18 01:08:24 +13:00
|
|
|
|
|
|
|
return {
|
|
|
|
subscribe: store.subscribe,
|
|
|
|
actions: { fetchScreens },
|
2020-11-14 04:42:32 +13:00
|
|
|
}
|
2020-11-18 01:08:24 +13:00
|
|
|
}
|
2020-11-14 04:42:32 +13:00
|
|
|
|
2020-11-18 01:08:24 +13:00
|
|
|
if (!window.bbSDKScreenStore) {
|
|
|
|
window.bbSDKScreenStore = createScreenStore()
|
2020-11-14 04:42:32 +13:00
|
|
|
}
|
2020-11-18 01:08:24 +13:00
|
|
|
|
|
|
|
export const screenStore = window.bbSDKScreenStore
|