Created
November 15, 2016 12:31
-
-
Save timwis/39a61c57b4e1b475151fc9e4968dd42a to your computer and use it in GitHub Desktop.
Test case demonstrating onload breaks with nested views
This file contains hidden or 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 html = require('choo/html') | |
const app = choo() | |
app.model({ | |
state: {}, | |
reducers: { | |
receive: (data, state) => ({}) | |
}, | |
effects: { | |
fetch: (data, state, send, done) => { | |
console.log('fetch') | |
send('receive', done) | |
} | |
} | |
}) | |
const Layout = (View) => (state, prev, send) => { | |
return html` | |
<main onload=${onload}> | |
<nav class="nav has-shadow"> | |
<div class="container"> | |
<a href="/" class="nav-item is-tab">Home</a> | |
<a href="/add" class="nav-item is-tab">Add</a> | |
</div> | |
</nav> | |
${View(state, prev, send)} | |
</main> | |
` | |
function onload () { | |
console.log('onload') | |
send('fetch') | |
} | |
} | |
const Home = (state, prev, send) => html`<div>Home</div>` | |
const Add = (state, prev, send) => html`<div>Add</div>` | |
app.router((route) => [ | |
route('/', Layout(Home)), | |
route('/add', Layout(Add)) | |
]) | |
const tree = app.start() | |
document.body.appendChild(tree) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment