Created
January 11, 2019 18:22
-
-
Save green3g/03d9267d2b99989e824d0af6b5063347 to your computer and use it in GitHub Desktop.
Dynamic event delegation
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
| Component.extend({ | |
| tag: 'panel-component', | |
| ViewModel: { | |
| collapsed: 'boolean', | |
| contentRenderer: { | |
| default(){ | |
| return stache(`<p>Hello world</p>`); | |
| } | |
| } | |
| }, | |
| view: ` | |
| <div class="wrapper"> | |
| <button on:click="collapsed = not(collapsed)">Close</button> | |
| {{#not(collapsed)}}{{contentRenderer(this)}}{{/not}} | |
| </div> | |
| ` | |
| }); | |
| // USAGE: | |
| const template = stache(`<button class="custom">Do stuff!</button>`); | |
| stache(`<panel-component contentRenderer:from="template" />`)({ | |
| template, | |
| // pass connected callback | |
| connectedCallback(el){ | |
| this.listenTo('button.custom click', () => { | |
| this.collapsed = !this.collapsed; | |
| }); | |
| }, | |
| // OR pass events?? | |
| events: { | |
| 'button.custom click': function(){ | |
| this.viewModel.collapsed = false; | |
| } | |
| } | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment