Skip to content

Instantly share code, notes, and snippets.

@thousand
Last active October 20, 2016 23:46
Show Gist options
  • Save thousand/1759cd4195953559784bd1a2c1f2a3bf to your computer and use it in GitHub Desktop.
Save thousand/1759cd4195953559784bd1a2c1f2a3bf to your computer and use it in GitHub Desktop.
New Twiddle
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'Ember Twiddle',
init() {
this._super(...arguments);
const store = this.get('store');
window.thingz = this.thingz = [];
this._defaultThing = store.createRecord('thing', {name: Math.random() });
this._addThing();
},
_addThing() {
const store = this.get('store');
this.thingz.unshiftObject(store.createRecord('thing', { name: Math.random() }))
this.thingz.pushObject(this._defaultThing);
},
actions: {
addThing() {
this._addThing();
}
}
});
import Model from "ember-data/model";
import attr from "ember-data/attr";
import { belongsTo, hasMany } from "ember-data/relationships";
export default Model.extend({
});
<h1 {{action "addThing"}}>Click to add thingz</h1>
<br>
{{#each thingz as |thing|}}
<li>{{thing.id}} &ndash; {{thing.name}}</li>
{{/each}}
<br>
{{outlet}}
<br>
<br>
{
"version": "0.10.6",
"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.9.0",
"ember-data": "2.9.0",
"ember-template-compiler": "2.9.0",
"ember-testing": "2.9.0"
},
"addons": {}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment