choo-resource
v1.0.1
Published
simple resource management for choo apps
Downloads
2
Readme
choo-resource
simple resource management for choo apps
Installation
$ npm install choo-resource
Usage
// index.js
var choo = require('choo')
var html = require('choo/html')
var link = require('choo-resource/link')
var app = choo()
app.use(require('choo-resource')())
// registers '/posts' and '/posts/:id' routes
// registers Post and Posts components in component cache
app.resource(
'/posts',
require('./views/posts'),
require('./components/posts')
)
app.resource(
'/posts/:id'
require('./views/post'),
require('./components/post'),
)
app.route('/', (state, emit) => {
return html`<body>
<ul>
<li>${link('All posts', '/posts')}</li>
<li>${link('Post 1', '/posts/1')}</li>
<li>${link('Post 2', '/posts/2')}</li>
</ul>
</body>`
})
app.mount('body')