This commit is contained in:
syuilo 2017-02-18 18:03:52 +09:00
parent 201f48d7e4
commit 6cd3c3e9ec
3 changed files with 44 additions and 53 deletions

42
src/web/app/dev/router.js Normal file
View file

@ -0,0 +1,42 @@
const route = require('page');
let page = null;
module.exports = me => {
route('/', index);
route('/apps', apps);
route('/app/new', newApp);
route('/app/:app', app);
route('*', notFound);
function index() {
mount(document.createElement('mk-index'));
}
function apps() {
mount(document.createElement('mk-apps-page'));
}
function newApp() {
mount(document.createElement('mk-new-app-page'));
}
function app(ctx) {
const el = document.createElement('mk-app-page');
el.setAttribute('app', ctx.params.app);
mount(el);
}
function notFound() {
mount(document.createElement('mk-not-found'));
}
// EXEC
route();
};
const riot = require('riot');
function mount(content) {
if (page) page.unmount();
const body = document.getElementById('app');
page = riot.mount(body.appendChild(content))[0];
}

View file

@ -1,51 +0,0 @@
# Router
#================================
route = require \page
page = null
module.exports = (me) ~>
# Routing
#--------------------------------
route \/ index
route \/apps apps
route \/app/new new-app
route \/app/:app app
route \* not-found
# Handlers
#--------------------------------
function index
mount document.create-element \mk-index
function apps
mount document.create-element \mk-apps-page
function new-app
mount document.create-element \mk-new-app-page
function app ctx
document.create-element \mk-app-page
..set-attribute \app ctx.params.app
.. |> mount
function not-found
mount document.create-element \mk-not-found
# Exec
#--------------------------------
route!
# Mount
#================================
riot = require \riot
function mount content
if page? then page.unmount!
body = document.get-element-by-id \app
page := riot.mount body.append-child content .0

View file

@ -3,8 +3,8 @@
*/ */
require('./tags'); require('./tags');
const boot = require('../boot.js'); const boot = require('../boot');
const route = require('./router.ls'); const route = require('./router');
/** /**
* Boot * Boot