Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save rtablada/248291d5de02ef29fcc27e29f911799c to your computer and use it in GitHub Desktop.
Save rtablada/248291d5de02ef29fcc27e29f911799c to your computer and use it in GitHub Desktop.
New Twiddle
import Ember from 'ember';
export default Ember.Component.extend({
didReceiveAttrs() {
this._super(...arguments);
const filterBy = this.get('filter');
if (filterBy !== null) {
this.set('items', this.filterItems(filterBy));
} else {
console.log('no filter');
}
},
filterItems(filterBy) {
return this.get('items').filter((item) => {
return item[filterBy] !== true
});
}
});
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'Ember Twiddle'
});
import Ember from 'ember';
export default Ember.Controller.extend({
actions: {
save() {
let person = this.store.createRecord('person', this.model);
person.save()
.then(() => {
// Whatever???
});
}
}
});
import Ember from 'ember';
import config from './config/environment';
const Router = Ember.Router.extend({
location: 'none',
rootURL: config.rootURL
});
Router.map(function() {
this.route('create')
});
export default Router;
import Ember from 'ember';
export default Ember.Route.extend({
model() {
return {
first: '',
last: '',
items: [{complete: false, accapted: false}, {complete: true, accapted: false}]
// Should be
// items: [{complete: false, accepted: false}, {complete: true, accepted: false}]
};
}
});
<h1>Welcome to {{appName}}</h1>
<br>
<br>
{{outlet}}
<br>
<br>
{{link-to "create" "create"}}
<h3>{{title}}</h3>
<ul>
{{#each items as |item|}}
<li>
<p>complete: {{item.complete}}</p>
<p>accepted: {{item.accepted}}</p>
</li>
{{/each}}
</ul>
<form onsubmit={{action "save"}}>
{{input value=model.first placeholder="First"}}
{{input value=model.last placeholder="Last"}}
<button>Save</button>
</form>
{{list-component title="Completed List" items=model.items filter="complete"}}
{{list-component title="Completed List" items=model.items filter="accepted"}}
import Ember from 'ember';
export default function destroyApp(application) {
Ember.run(application, 'destroy');
}
import Resolver from '../../resolver';
import config from '../../config/environment';
const resolver = Resolver.create();
resolver.namespace = {
modulePrefix: config.modulePrefix,
podModulePrefix: config.podModulePrefix
};
export default resolver;
import Ember from 'ember';
import Application from '../../app';
import config from '../../config/environment';
const { run } = Ember;
const assign = Ember.assign || Ember.merge;
export default function startApp(attrs) {
let application;
let attributes = assign({rootElement: "#test-root"}, config.APP);
attributes = assign(attributes, attrs); // use defaults, but you can override;
run(() => {
application = Application.create(attributes);
application.setupForTesting();
application.injectTestHelpers();
});
return application;
}
import resolver from './helpers/resolver';
import {
setResolver
} from 'ember-qunit';
setResolver(resolver);
{
"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