2020-09-21 01:19:12 +02:00
|
|
|
require('babel-polyfill');
|
2019-09-10 00:19:02 +02:00
|
|
|
|
2020-09-21 01:19:12 +02:00
|
|
|
const choo = require('choo');
|
2019-09-07 21:54:44 +02:00
|
|
|
|
2020-09-21 01:19:12 +02:00
|
|
|
const config = require('./config.json');
|
|
|
|
const { appRoutes } = require('./appRoutes');
|
|
|
|
const { appListeners } = require('./appListeners');
|
|
|
|
const { appState } = require('./appState.js');
|
|
|
|
const { appUtilities } = require('./appUtilities.js');
|
2019-09-07 21:54:44 +02:00
|
|
|
|
2020-09-21 01:19:12 +02:00
|
|
|
function frontend() {
|
|
|
|
const app = choo();
|
2019-09-07 21:54:44 +02:00
|
|
|
|
2020-09-21 01:19:12 +02:00
|
|
|
if (process.env.NODE_ENV !== 'production') {
|
|
|
|
// Only runs in development and will be stripped from production build.
|
|
|
|
app.use(require('choo-devtools')()); // Exposes `choo` to the console for debugging!
|
|
|
|
}
|
|
|
|
|
|
|
|
app.use((state, emitter) => {
|
|
|
|
app.siteConfig = config;
|
|
|
|
appUtilities(app);
|
|
|
|
});
|
|
|
|
|
|
|
|
app.use((state, emitter) => {
|
|
|
|
appState(app, state);
|
2019-09-07 21:54:44 +02:00
|
|
|
|
2020-09-21 01:19:12 +02:00
|
|
|
// Listeners
|
|
|
|
appListeners(app, state, emitter);
|
|
|
|
});
|
2019-09-09 22:22:09 +02:00
|
|
|
|
2020-09-21 01:19:12 +02:00
|
|
|
// Routes
|
|
|
|
appRoutes(app);
|
2019-09-07 21:54:44 +02:00
|
|
|
|
2020-09-21 01:19:12 +02:00
|
|
|
app.mount('body'); // Overwrite the `<body>` tag with the content of the Choo app
|
2019-09-07 21:54:44 +02:00
|
|
|
|
2020-09-21 01:19:12 +02:00
|
|
|
return app;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (typeof window !== 'undefined') {
|
|
|
|
frontend();
|
|
|
|
}
|
2019-09-07 21:54:44 +02:00
|
|
|
|
2020-09-21 01:19:12 +02:00
|
|
|
module.exports = frontend;
|