1
0
Fork 0
mirror of synced 2024-06-01 10:09:48 +12:00

code review, simplify iframeTemplate

This commit is contained in:
Martin McKeaveney 2021-11-10 12:12:33 +01:00
parent 753d2f51bc
commit b66d76f010
3 changed files with 12 additions and 21 deletions

View file

@ -95,12 +95,12 @@
const handlers = {
[MessageTypes.READY]: () => {
// Initialise the app when mounted
// Display preview immediately if the intelligent loading feature
// is not supported
if ($store.clientFeatures.messagePassing) {
if (!loading) return
}
// Display preview immediately if the intelligent loading feature
// is not supported
if (!$store.clientFeatures.intelligentLoading) {
loading = false
}
@ -119,9 +119,8 @@
}
onMount(() => {
if ($store.clientFeatures.messagePassing) {
window.addEventListener("message", receiveMessage)
} else {
window.addEventListener("message", receiveMessage)
if (!$store.clientFeatures.messagePassing) {
// Legacy - remove in later versions of BB
iframe.contentWindow.addEventListener("ready", () => {
receiveMessage({ data: { type: MessageTypes.READY }})
@ -132,15 +131,14 @@
// Add listener for events sent by client library in preview
iframe.contentWindow.addEventListener("bb-event", handleBudibaseEvent)
iframe.contentWindow.addEventListener("keydown", handleKeydownEvent)
}
}
})
// Remove all iframe event listeners on component destroy
onDestroy(() => {
if (iframe.contentWindow) {
if ($store.clientFeatures.messagePassing) {
window.removeEventListener("message", receiveMessage)
} else {
window.removeEventListener("message", receiveMessage)
if (!$store.clientFeatures.messagePassing) {
// Legacy - remove in later versions of BB
iframe.contentWindow.removeEventListener("bb-event", handleBudibaseEvent)
iframe.contentWindow.removeEventListener("keydown", handleKeydownEvent)

View file

@ -65,7 +65,6 @@ export default `
theme,
customTheme,
previewDevice,
messagePassing
} = parsed
// Set some flags so the app knows we're in the builder
@ -90,11 +89,7 @@ export default `
throw "The client library couldn't be loaded"
}
} catch (error) {
if (messagePassing) {
window.parent.postMessage({ type: "error", error })
} else {
window.dispatchEvent(new CustomEvent("error", { detail: error }))
}
window.parent.postMessage({ type: "error", error })
}
}
@ -104,7 +99,6 @@ export default `
})
window.parent.postMessage({ type: "ready" })
window.dispatchEvent(new Event("ready"))
</script>
</head>
<body/>

View file

@ -81,13 +81,12 @@ export function createAuthStore() {
}
async function setInitInfo(info) {
const response = await api.post(`/api/global/auth/init`, info)
const json = await response.json()
await api.post(`/api/global/auth/init`, info)
auth.update(store => {
store.initInfo = json
store.initInfo = info
return store
})
return json
return info
}
async function getInitInfo() {
@ -102,7 +101,7 @@ export function createAuthStore() {
return {
subscribe: store.subscribe,
setOrganisation: setOrganisation,
setOrganisation,
getInitInfo,
setInitInfo,
checkQueryString: async () => {