Last active
July 26, 2017 07:12
-
-
Save akiva/fed503aed3a76be6bbf1dada30f9018b 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
const app = require('choo')() | |
const html = require('choo/html') | |
app.use(function (state, emitter) { | |
state.loggedIn = false | |
emitter.prependListener('DOMContentLoaded', function () { | |
if (state.route !== '/shazam' && !state.loggedIn) { | |
emitter.emit('pushState', '/shazam') | |
emitter.emit('render') | |
} | |
}) | |
emitter.prependListener('navigate', function () { | |
console.log('state.route:', state.route, window.location.pathname) | |
state.route = window.location.pathname | |
emitter.once('render', function () { | |
console.log('state.route:', state.route, window.location.pathname) | |
}) | |
}) | |
emitter.on('navigate', function () { | |
console.log('Post-navigate event route', state.route) | |
}) | |
}) | |
app.route('/', function (state, emit) { | |
return html` | |
<body> | |
<p>Foo bar baz quux</p> | |
</body> | |
` | |
}) | |
app.route('/shazam', function (state, emit) { | |
return html` | |
<body> | |
<p>Shazam</p> | |
</body> | |
` | |
}) | |
if (module.parent) module.exports = app | |
else app.mount('body') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment