UNPKG

cordova-elm-template-jumpstart

Version:

Cordova template to jumpstart development using Elm and Webpack

46 lines (42 loc) 1.45 kB
/* * This file is responsible for launching Elm and connecting it to the outside world. * * The returned function is assumed to be run *after* all the initialization has executed. * * If you want to do something with the function (eg: attach a handler to a port), then * define that as a JavaScript module in ./launchElm.d -- we require every *.js file in * that directory. We assume that it exports a function, and we pass that function the * app as the first argument. * */ import Promise from "bluebird"; import _ from "lodash"; const appHandlers = require.context( "./launchElm.d/", // Directory where the handlers live true, // Whether or not to look in subdirectories /\.js$/i // Filename regex defining files to process ); module.exports = Promise.try( () => console.info("Starting Elm application") ).then( () => require("./elm/Main.elm") ).then(Elm => Elm.Main.fullscreen({ assets: require("./assets.js"), }) ).tap( () => console.info("Launched application; now processing app handlers") ).then( app => { console.info("Passing app into handlers", app, appHandlers.keys()); return Promise.map( appHandlers.keys(), appHandlers ).map( handlerModule => handlerModule(app) ).all().return(app) } ).catch(e => { console.error("Error launching application", e); throw e; }).finally( () => console.info("Done launching application and processing app handlers") )