models: sturdify namespaces

This commit is contained in:
Yoshua Wuyts
2016-05-23 03:32:14 +09:00
parent 0be2337605
commit 24b9be7c8d
4 changed files with 77 additions and 47 deletions
+20 -15
View File
@@ -1,26 +1,31 @@
const choo = require('../')
const choo = require('../../')
const app = choo()
app.model('title', {
state: { title: 'my-demo-app' },
app.model({
namespace: 'input',
state: {
title: 'my demo app'
},
reducers: {
'update': (action, state) => ({ title: action.payload })
update: (action, state) => ({ title: action.payload })
},
effects: {
'update': (action, state, send) => (document.title = action.payload)
update: (action, state, send) => (document.title = action.payload)
}
})
const mainView = (params, state, send) => choo.view`
<main class="app">
<h1>${state.title}</h1>
<label>Set the title</label>
<input
type="text"
placeholder=${state.title}
oninput=${(e) => send('title:update', { payload: e.target.value })}>
</main>
`
const mainView = (params, state, send) => {
return choo.view`
<main class="app">
<h1>${state.input.title}</h1>
<label>Set the title</label>
<input
type="text"
placeholder=${state.input.title}
oninput=${(e) => send('input:update', { payload: e.target.value })}>
</main>
`
}
app.router((route) => [
route('/', mainView)