budibase/packages/builder/src/builderStore/index.js

48 lines
1.3 KiB
JavaScript
Raw Normal View History

2020-11-04 18:09:45 +01:00
import { getFrontendStore } from "./store/frontend"
import { getBackendUiStore } from "./store/backend"
import { getAutomationStore } from "./store/automation/"
import { getThemeStore } from "./store/theme"
import { derived } from "svelte/store"
import analytics from "analytics"
2019-07-13 11:35:57 +02:00
2020-11-04 18:09:45 +01:00
export const store = getFrontendStore()
export const backendUiStore = getBackendUiStore()
export const automationStore = getAutomationStore()
export const themeStore = getThemeStore()
2019-07-13 11:35:57 +02:00
export const allScreens = derived(store, $store => {
let screens = []
if ($store.pages == null) {
return screens
}
for (let page of Object.values($store.pages)) {
screens = screens.concat(page._screens)
}
return screens
})
export const currentScreens = derived(store, $store => {
const currentScreens = $store.pages[$store.currentPageName]?._screens
if (currentScreens == null) {
return []
}
2020-11-06 13:31:47 +01:00
return Array.isArray(currentScreens)
? currentScreens
: Object.values(currentScreens)
})
export const selectedPage = derived(store, $store => {
if (!$store.pages) return null
return $store.pages[$store.currentPageName || "main"]
})
2019-07-13 11:35:57 +02:00
export const initialise = async () => {
try {
await analytics.activate()
analytics.captureEvent("Builder Started")
} catch (err) {
console.log(err)
}
2020-05-07 11:53:34 +02:00
}