2017-10-31 13:17:14 -05:00
|
|
|
import * as riot from 'riot';
|
2017-11-13 03:05:35 -06:00
|
|
|
import * as route from 'page';
|
2017-10-31 13:17:14 -05:00
|
|
|
let page = null;
|
|
|
|
|
2017-11-15 12:06:52 -06:00
|
|
|
export default () => {
|
2017-10-31 13:17:14 -05:00
|
|
|
route('/', index);
|
|
|
|
route('/:channel', channel);
|
|
|
|
route('*', notFound);
|
|
|
|
|
|
|
|
function index() {
|
|
|
|
mount(document.createElement('mk-index'));
|
|
|
|
}
|
|
|
|
|
|
|
|
function channel(ctx) {
|
|
|
|
const el = document.createElement('mk-channel');
|
|
|
|
el.setAttribute('id', ctx.params.channel);
|
|
|
|
mount(el);
|
|
|
|
}
|
|
|
|
|
|
|
|
function notFound() {
|
|
|
|
mount(document.createElement('mk-not-found'));
|
|
|
|
}
|
|
|
|
|
|
|
|
// EXEC
|
2017-11-13 03:05:35 -06:00
|
|
|
(route as any)();
|
2017-10-31 13:17:14 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
function mount(content) {
|
|
|
|
if (page) page.unmount();
|
|
|
|
const body = document.getElementById('app');
|
|
|
|
page = riot.mount(body.appendChild(content))[0];
|
|
|
|
}
|