Skip to content

Instantly share code, notes, and snippets.

@koriroys
Last active October 14, 2015 15:48
Show Gist options
  • Save koriroys/95bc8f15569b708cf876 to your computer and use it in GitHub Desktop.
Save koriroys/95bc8f15569b708cf876 to your computer and use it in GitHub Desktop.
modified twice in the single render
import Ember from 'ember';
export default Ember.Controller.extend({
appName:'Ember Twiddle'
});
import Ember from 'ember';
export default Ember.Route.extend({
myStore: Ember.inject.service('my-store'),
model() {
return this.get('myStore.records');
}
});
<h1>Welcome to {{appName}}</h1>
<br>
<br>
{{outlet}}
{{record-count records=model}}
{{new-record}}
<br>
<br>
import Ember from 'ember';
export default Ember.Component.extend({
myStore: Ember.inject.service('my-store'),
actions: {
create() {
let newRecord = Ember.Object.create({ name: "white" });
this.get('myStore').create(newRecord);
}
}
});
<button {{action 'create'}}>Create new record</button>
import Ember from 'ember';
export default Ember.Component.extend({
recordCount: Ember.computed('records.[]', function() {
return this.get('records.length');
})
});
<p>There are {{recordCount}} records</p>
import Ember from 'ember';
export default Ember.Service.extend({
records: null,
init() {
this._super(...arguments);
this.set('records', [
Ember.Object.create({ name: "black" })
]);
},
create(record) {
this.get('records').pushObject(record);
}
});
{
"version": "0.4.11",
"dependencies": {
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js",
"ember": "https://cdnjs.cloudflare.com/ajax/libs/ember.js/1.13.10/ember.debug.js",
"ember-data": "https://cdnjs.cloudflare.com/ajax/libs/ember-data.js/1.13.13/ember-data.js",
"ember-template-compiler": "https://cdnjs.cloudflare.com/ajax/libs/ember.js/1.13.10/ember-template-compiler.js"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment