Skip to content

Instantly share code, notes, and snippets.

@yaobind
Last active August 7, 2019 18:08
Show Gist options
  • Save yaobind/b5c9639304a36ae9f93e1e22b393a7c2 to your computer and use it in GitHub Desktop.
Save yaobind/b5c9639304a36ae9f93e1e22b393a7c2 to your computer and use it in GitHub Desktop.
how bubbles=false works
import Ember from 'ember';
export default Ember.Component.extend({
tagName: 'button',
});
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'Event Bubbling Play Ground',
actions: {
handleChildClickNoop() {
// no op
console.log('handleChildClickNoop');
},
handleChildClickAndReturnFalse() {
console.log('handleChildClickAndReturnFalse')
return false;
},
handleParentClick() {
alert('parent clicked');
},
},
});
<h1>Welcome to {{appName}}</h1>
<br>
<br>
{{outlet}}
<br>
<br>
<button {{action 'handleParentClick'}}>
<button {{action 'handleChildClickNoop' bubbles=false}}>1-YES</button>
<button {{action 'handleChildClickAndReturnFalse'}}>2-NO</button>
<button {{action (action 'handleChildClickNoop') bubbles=false}}>3-YES</button>
<button {{action (action 'handleChildClickNoop' bubbles=false)}}>4-NO</button>
<button {{action (action 'handleChildClickAndReturnFalse')}}>5-NO</button>
{{#my-component click=(action 'handleChildClickAndReturnFalse')}}
6-YES
{{/my-component}}
{{#my-component click=(action 'handleChildClickNoop' bubbles=false)}}
7-NO
{{/my-component}}
</button>
{
"version": "0.15.1",
"EmberENV": {
"FEATURES": {}
},
"options": {
"use_pods": false,
"enable-testing": false
},
"dependencies": {
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.js",
"ember": "3.4.3",
"ember-template-compiler": "3.4.3",
"ember-testing": "3.4.3"
},
"addons": {
"ember-data": "3.4.2"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment