Created
January 4, 2017 04:05
-
-
Save rosemarydotworld/a3aef0cba9cdc1e119b1da735e54daa7 to your computer and use it in GitHub Desktop.
Namespacing Models in Choo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const choo = require('choo'); | |
const app = choo(); | |
app.model(require('./model-things')); | |
app.model(require('./model-stuff')); | |
const view = (state, prev, send) => html` | |
<main> | |
<button onclick=${e => send('things:notGood')}>things aren't good</button> | |
<button onclick=${e => send('stuff:notBad')}>stuff isn't bad</button> | |
</main> | |
`; | |
app.router((route) => [ | |
route('/', view) | |
]); | |
const tree = app.start(); | |
document.body.appendChild(tree); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module.exports = { | |
namespace: 'stuff', | |
state: { | |
bad: true | |
}, | |
reducers: { | |
notBad: (data, state, send, prev) => { | |
{ bad: false } | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module.exports = { | |
namespace: 'things', | |
state: { | |
good: true | |
}, | |
reducers: { | |
notGood: (data, state, send, prev) => { | |
{ good: false } | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment