Skip to content

Instantly share code, notes, and snippets.

@kmiyashiro
Created January 9, 2018 20:06
Show Gist options
  • Save kmiyashiro/3aaa88ab44999421df40360b8211c294 to your computer and use it in GitHub Desktop.
Save kmiyashiro/3aaa88ab44999421df40360b8211c294 to your computer and use it in GitHub Desktop.
Editing cached value of new computed array
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'Ember Twiddle',
things: [1, 2, 3],
computedArray: Ember.computed('things.[]', function() {
return Ember.A(this.get('things').slice());
}),
actions: {
pushToComputed() {
this.get('computedArray').pushObject('wombat');
},
pushToThings() {
this.get('things').pushObject(4);
}
}
});
<h1>Welcome to {{appName}}</h1>
<br>
<br>
{{outlet}}
<h2>Original</h2>
{{#each things as |thing|}}
{{thing}}<br>
{{/each}}
<h2>Computed</h2>
{{#each computedArray as |thing|}}
{{thing}}<br>
{{/each}}
<button onclick={{action 'pushToComputed'}}>computed</button>
<button onclick={{action 'pushToThings'}}>things</button>
<br>
<br>
{
"version": "0.13.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.16.2",
"ember-template-compiler": "2.16.2",
"ember-testing": "2.16.2"
},
"addons": {
"ember-data": "2.16.3"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment