Created
April 20, 2017 13:48
-
-
Save kitop/901c097e5bda81405c7edee263b8ad33 to your computer and use it in GitHub Desktop.
webpack & elm
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
const Elm = require("../../elm/HelloWorld.elm") | |
window.registerApp({ HelloWorld: Elm.HelloWorld }) |
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
(function(window) { | |
let apps = {} | |
window.registerApp = newApps => { | |
apps = { | |
...apps, | |
...newApps | |
}; | |
} | |
const load = function() { | |
Array.prototype.slice.call(document.querySelectorAll('[data-elm-app]')).forEach(function(element) { | |
const app = apps[element.dataset.elmApp] | |
const propsJson = element.dataset.props | |
const props = propsJson ? JSON.parse(propsJson) : {} | |
app.embed(element, props); | |
}) | |
} | |
document.addEventListener('DOMContentLoaded', load) | |
if (document.readyState == 'complete') { | |
load() | |
} | |
})(window) |
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
module ElmHelper | |
def elm_app(name, props = {}, html_options = {}) | |
if props.has_key?(:elm_app) | |
content_tag :div do | |
content_tag :span, "elm_app is a reserved keyword. Your props need to not contain it" | |
end | |
return | |
end | |
html_options[:data] = { | |
elm_app: name, | |
props: props.as_json | |
} | |
content_tag :div, nil, html_options | |
end | |
end |
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
<%= elm_app "HelloWorld" %> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment