Skip to content

Instantly share code, notes, and snippets.

@v3ss0n
Forked from alexspeller/models.account.js
Last active January 6, 2017 18:33
Show Gist options
  • Save v3ss0n/8f51d4a6e9c9ae5030e4db2ed6c898d9 to your computer and use it in GitHub Desktop.
Save v3ss0n/8f51d4a6e9c9ae5030e4db2ed6c898d9 to your computer and use it in GitHub Desktop.
New Twiddle
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'Ember Twiddle',
allInvoices: Ember.computed(function() {
return this.store.peekAll('invoice');
})
});
import Model from "ember-data/model";
import attr from "ember-data/attr";
import { belongsTo, hasMany } from "ember-data/relationships";
export default Model.extend({
invoices: hasMany(),
name: attr('string')
});
import Model from "ember-data/model";
import attr from "ember-data/attr";
import { belongsTo, hasMany } from "ember-data/relationships";
export default Model.extend({
title: attr('string'),
account: belongsTo()
});
import Ember from 'ember';
export default Ember.Route.extend({
model() {
this.store.pushPayload({
data: {
type: "accounts",
id: 1,
attributes: {
name: 'my account'
}
}
});
return this.store.peekRecord('account', 1);
},
loadAnInvoice() {
this.store.pushPayload({
data: {
type: "invoices",
id: Math.random().toString(),
attributes: {
title: `Invoice ${Math.random().toString()}`
},
relationships: {
account: {
data: {
type: 'accounts',
id: '1'
}
}
}
}
});
},
actions: {
nextPage() {
for(let i = 0; i < 10; i++) {
this.loadAnInvoice();
}
}
}
});
<h1>{{model.name}}</h1>
<button {{action 'nextPage'}}>Next Page</button>
<h2>Invoices: {{model.invoices.length}}</h2>
<ul>
{{#each model.invoices as |invoice|}}
<li>{{invoice.title}}</li>
{{/each}}
</ul>
{
"version": "0.9.2",
"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.6.0",
"ember-data": "2.6.0",
"ember-template-compiler": "2.6.0"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment