Skip to content

Instantly share code, notes, and snippets.

@2hu12
Last active November 21, 2019 07:53
Show Gist options
  • Save 2hu12/f3b639dc56f86b48dd19a0ca5bec8616 to your computer and use it in GitHub Desktop.
Save 2hu12/f3b639dc56f86b48dd19a0ca5bec8616 to your computer and use it in GitHub Desktop.
simple helper vs calss helper reference update which would be fixed by octane
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'Ember Twiddle',
arr: [],
actions: {
emptyArr() {
this.set('arr', []);
},
nonEmptyArr() {
this.set('arr', [1]);
},
push(x) {
this.arr.pushObject(x);
},
pop() {
this.arr.popObject();
}
}
});
/*import { helper } from '@ember/component/helper';
import { isEmpty } from '@ember/utils';
export default helper(function emptyHelper([obj]) {
console.log('calling empty heler with:', obj);
return isEmpty(obj);
});*/
import Helper from '@ember/component/helper';
import { computed, get, observer, set } from '@ember/object';
import { equal } from '@ember/object/computed';
export default Helper.extend({
object: [],
/*isEmpty: computed('object.length', function () {
return get(this, 'object.length') === 0;
}).readOnly(),*/
isEmpty: equal('object.length', 0),
onChange: observer('object.length', function() {
this.recompute();
}),
compute([obj]) {
set(this, 'object', obj);
return get(this, 'isEmpty');
}
});
this.arr is empty: {{empty this.arr}}
<br>
this.arr.length: {{this.arr.length}}
<br>
<br>
<button {{action "push" 1}}>push</button>
<button {{action "pop"}}>pop</button>
<button {{action "nonEmptyArr"}}>new non empty arr</button>
<button {{action "emptyArr"}}>new empty arr</button>
{{outlet}}
<br>
<br>
{
"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