Created
November 17, 2019 18:30
-
-
Save maxfarseer/8b40db540fb30a404b525801b90bc058 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- ... --> | |
<script src="/elm.js"></script> | |
<script> | |
const errorLogger = error => console.error(`App Error: ${error}`); | |
const node = document.querySelector('#app'); | |
// add flags here | |
const flags = {} | |
try { | |
const app = Elm.Main.init({ node, flags }); | |
// Подписывамся на команду sendDataToJs | |
// создаем новое кастомное событие "draw-square" | |
// в которое передаем объект с любыми данными, в нашем случае base64 картинку | |
// в которой закодирован фиолетовый квадрат | |
app.ports.sendDataToJs.subscribe((base64path) => { | |
const event = new CustomEvent('draw-square', { 'detail': base64path }); | |
const customCanvas = document.getElementsByTagName('custom-canvas')[0]; | |
customCanvas.dispatchEvent(event); | |
}); | |
} catch (e) { | |
errorLogger(e); | |
node.textContent = 'An error occurred while initializing the app'; | |
} | |
</script> | |
<!-- ... --> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment