Skip to content

Instantly share code, notes, and snippets.

@givanse
Last active March 9, 2017 09:16
Show Gist options
  • Save givanse/3789f34da7d5fba51d7d069a7b51cdbf to your computer and use it in GitHub Desktop.
Save givanse/3789f34da7d5fba51d7d069a7b51cdbf to your computer and use it in GitHub Desktop.
Two-way and One-way
import Ember from 'ember';
export default Ember.Component.extend({
actions: {
oneWayInputUpdate: function(value) {
this.attrs.updateOneWay(value);
}
}
});
import Ember from 'ember';
export default Ember.Component.extend({
twoWay: 'two-way data bound',
oneWay: 'one-way data bound',
actions: {
updateOneWay: function(oneWay) {
this.set('oneWay', oneWay);
}
}
});
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'Ember Twiddle'
});
<h1>Two-way and One-way</h1>
{{outlet}}
<br>
<br>
{{! Best practice: Use the input element instead of the input helper. }}
two way: {{input value=twoWay}}
<br>
one way: <input value={{oneWay}}
onblur={{action "oneWayInputUpdate" value="target.value"}}
/>
{{yield}}
Parent component:
<br>
<br>
two way: {{twoWay}}
<br>
one way: {{oneWay}}
<br>
<br>
Child component:
<br>
<br>
<!--
Closure actions, v +1.13
function-passing solution to replace
the old action bubbling mechanism
http://emberjs.com/blog/2015/06/12/ember-1-13-0-released.html#toc_closure-actions
http://alexdiliberto.com/posts/ember-closure-actions/
-->
{{child-component twoWay=twoWay
oneWay=oneWay
updateOneWay=(action "updateOneWay")}}
{{yield}}
{{parent-component}}
{
"version": "0.11.1",
"EmberENV": {
"FEATURES": {}
},
"options": {
"use_pods": false,
"enable-testing": false
},
"dependencies": {
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js",
"ember": "2.11.0",
"ember-data": "2.11.0",
"ember-template-compiler": "2.11.0",
"ember-testing": "2.11.0"
},
"addons": {}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment