Skip to content

Instantly share code, notes, and snippets.

@ryanto
Last active February 2, 2017 21:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ryanto/eef78339cea0f0eaf8c131cb2ae1b3e9 to your computer and use it in GitHub Desktop.
Save ryanto/eef78339cea0f0eaf8c131cb2ae1b3e9 to your computer and use it in GitHub Desktop.
one way mutable value that resets
import Ember from 'ember';
export default Ember.Component.extend({
didReceiveAttrs() {
this._super(...arguments);
this.set('downstream', this.get('upstream'));
}
});
import Ember from 'ember';
export default Ember.Controller.extend({
upstream: 100,
actions: {
add100ToUpstream() {
this.set('upstream', this.get('upstream') + 100);
}
}
});
<h2>From the application controller</h2>
Upstream: {{upstream}}<br/>
<br/>
<a href="#" {{action "add100ToUpstream"}}>Add 100 to upstream</a> <br/>
<br />
<hr />
{{my-component upstream=upstream}}
<h2>From the component</h2>
Upstream: {{upstream}}<br/>
Downstream: {{downstream}}<br/>
<br/>
<a href="#" {{action (mut downstream) 300}}>Set downstream to 300</a> <br/>
{
"version": "0.11.0",
"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.10.2",
"ember-data": "2.11.0",
"ember-template-compiler": "2.10.2",
"ember-testing": "2.10.2"
},
"addons": {}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment