Skip to content

Instantly share code, notes, and snippets.

@rosemarydotworld
Created January 4, 2017 04:05
Show Gist options
  • Save rosemarydotworld/a3aef0cba9cdc1e119b1da735e54daa7 to your computer and use it in GitHub Desktop.
Save rosemarydotworld/a3aef0cba9cdc1e119b1da735e54daa7 to your computer and use it in GitHub Desktop.
Namespacing Models in Choo
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);
module.exports = {
namespace: 'stuff',
state: {
bad: true
},
reducers: {
notBad: (data, state, send, prev) => {
{ bad: false }
}
}
}
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