Skip to content

Instantly share code, notes, and snippets.

@nightire
Created September 29, 2016 16:25
Show Gist options
  • Save nightire/aa5726e3e6461a7932a902bf31c03f6b to your computer and use it in GitHub Desktop.
Save nightire/aa5726e3e6461a7932a902bf31c03f6b to your computer and use it in GitHub Desktop.
Why is Zero???
import Ember from 'ember';
export default Ember.Controller.extend({
foo: 0,
actions: {
toggle(property) {
this.incrementProperty(property);
},
reset(property) {
this.set(property, 0);
}
}
});
{{!--
Outside foo: {{foo}} <br>
Outside readonly foo: {{readonly foo}} <br>
Outside unbound foo: {{unbound foo}}
--}}
<hr>
{{change-foo originFoo=foo
unboundFoo=(unbound foo)
readonlyFoo=(readonly foo)}}
<hr>
<button type="button" onclick={{action "toggle" "foo"}}>
Update Original Foo from Outside
</button>
<button type="button" onclick={{action "reset" "foo"}}>
Reset to 0
</button>
import Ember from 'ember';
export default Ember.Component.extend({
didReceiveAttrs() {
this._super(...arguments);
console.log('Receive: ', this.get('unboundFoo'));
},
didUpdateAttrs() {
this._super(...arguments);
console.log('Update: ', this.get('unboundFoo'));
},
actions: {
update(property) {
this.incrementProperty(property);
}
}
});
Original foo: {{originFoo}} <br>
Readonly foo: {{readonlyFoo}} <br>
Unbound foo: {{unboundFoo}} <br>
<br>
<button type="button"
onclick={{action "update" "readonlyFoo"}}>
Update Readonly Foo from Inside
</button>
<button type="button"
onclick={{action "update" "unboundFoo"}}>
Update Unbound Foo from Inside
</button>
{{yield}}
{
"version": "0.10.5",
"EmberENV": {
"FEATURES": {}
},
"options": {
"use_pods": true,
"enable-testing": false
},
"dependencies": {
"jquery": "//cdnjs.cloudflare.com/ajax/libs/jquery/3.1.1/jquery.js",
"ember": "beta",
"ember-data": "beta",
"ember-template-compiler": "beta",
"ember-testing": "beta"
},
"addons": {}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment