Two-way binding inside each blocks
Last active
February 22, 2017 20:51
-
-
Save Rich-Harris/115f8c1ae72c3e8b4eafedc0937439ff to your computer and use it in GitHub Desktop.
Two-way binding inside {{#each}} blocks
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
bundle.js | |
node_modules | |
.vscode | |
.DS_Store | |
cleanup.sh |
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
<div class='component'> | |
<input bind:value> | |
</div> |
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
<html> | |
<body> | |
<main></main> | |
<script src='bundle.js'></script> | |
</body> | |
</html> |
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
<section> | |
<h2>direct</h2> | |
{{#each a as x}} | |
<!--TODO this doesn't work with components!--> | |
<!--<Component bind:value='prop'/>--> | |
<input bind:value='x'> | |
{{/each}} | |
<p>{{a.join(', ')}}</p> | |
</section> | |
<section> | |
<h2>nested</h2> | |
{{#each b as x}} | |
<!--TODO this doesn't work with components!--> | |
<!--<Component bind:value='prop'/>--> | |
<input bind:value='x.name'> | |
{{/each}} | |
<p>{{b.map(getName).join(', ')}}</p> | |
</section> | |
<script> | |
import Component from './Component.html'; | |
export default { | |
data: function () { | |
return { | |
a: [ 'foo', 'bar', 'baz' ], | |
b: [{ name: 'foo' }, { name: 'bar' }, { name: 'baz' }], | |
getName: function ( x ) { | |
return x.name; | |
} | |
} | |
}, | |
components: { | |
Component | |
} | |
}; | |
</script> |
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
import Main from './Main.html'; | |
new Main({ | |
target: document.querySelector( 'main' ) | |
}); |
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
{ | |
"devDependencies": { | |
"rollup": "^0.41.4", | |
"rollup-plugin-svelte": "^1.6.0" | |
}, | |
"scripts": { | |
"build": "rollup -c" | |
} | |
} |
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
import svelte from 'rollup-plugin-svelte'; | |
export default { | |
entry: 'main.js', | |
dest: 'bundle.js', | |
format: 'iife', | |
plugins: [ svelte() ] | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment