Skip to content

Instantly share code, notes, and snippets.

@glenjamin
Created June 10, 2016 14:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save glenjamin/71e53938a1e7a3b3a20c3056bc47f9c6 to your computer and use it in GitHub Desktop.
Save glenjamin/71e53938a1e7a3b3a20c3056bc47f9c6 to your computer and use it in GitHub Desktop.
A sketch of an approach for making it slightly easier to share elm native modules.
(function ElmNativeWrapper(name, actualNativeModule) {
var initialised = false;
window[name] = {
init: function(appname) {
// Could use Object.keys(window) here to try and detect if the name is wrong
window[munge(appname) + "$Native_" + name] = actualNativeModule();
initialised = true;
}
}
setTimeout(function() {
if (!initialised) {
console.error("Native module " + name + " was not initialised");
}
}, 1000);
function munge() {
// TODO
}
})(
"ElmFirebase",
function actualNativeModule() {
return {
whatever: "you",
need: "here"
};
}
);
ElmFirebase.init("glenjamin/haxx");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment