diff --git a/src/web/app/dev/router.js b/src/web/app/dev/router.js new file mode 100644 index 000000000..71c098463 --- /dev/null +++ b/src/web/app/dev/router.js @@ -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]; +} diff --git a/src/web/app/dev/router.ls b/src/web/app/dev/router.ls deleted file mode 100644 index ac408b36e..000000000 --- a/src/web/app/dev/router.ls +++ /dev/null @@ -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 diff --git a/src/web/app/dev/script.js b/src/web/app/dev/script.js index c9c5ee51e..e0644c263 100644 --- a/src/web/app/dev/script.js +++ b/src/web/app/dev/script.js @@ -3,8 +3,8 @@ */ require('./tags'); -const boot = require('../boot.js'); -const route = require('./router.ls'); +const boot = require('../boot'); +const route = require('./router'); /** * Boot