Skip to content

Instantly share code, notes, and snippets.

@derrickshowers
Created March 28, 2016 02:09
Show Gist options
  • Save derrickshowers/0d78187fb472bd6858a6 to your computer and use it in GitHub Desktop.
Save derrickshowers/0d78187fb472bd6858a6 to your computer and use it in GitHub Desktop.
Ember Arrays
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'Ember Arrays',
foo: [],
bar: Ember.computed('foo', function() {
console.log('bar called');
}),
baz: Ember.computed('foo.[]', function() {
console.log('baz called');
}),
actions: {
addObject() {
this.get('foo').pushObject({});
console.log(this.get('foo.length'));
},
addObjectJS() {
let foo = this.get('foo');
foo.push({});
console.log(foo === this.get('foo'));
this.set('foo', foo);
console.log(this.get('foo'));
},
replaceObject() {
this.set('foo', []);
},
outputFoo() {
console.dir(this.get('foo'));
}
}
});
<h1>Welcome to {{appName}}</h1>
<p>See console output</p>
<button {{action "addObject"}}>Add object</button>
<button {{action "addObjectJS"}}>Push object (JS)</button>
<button {{action "replaceObject"}}>Replace object</button>
<button {{action "outputFoo"}}>Output foo</button>
{{bar}}{{baz}}
{
"version": "0.7.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": "release",
"ember-data": "release",
"ember-template-compiler": "release"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment