Skip to content

Instantly share code, notes, and snippets.

@stefanpenner
Created March 9, 2017 18:06
Show Gist options
  • Save stefanpenner/ae405e979ed5ab30471d4cda44999ab7 to your computer and use it in GitHub Desktop.
Save stefanpenner/ae405e979ed5ab30471d4cda44999ab7 to your computer and use it in GitHub Desktop.
New Twiddle
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'Ember Twiddle'
});
import Ember from 'ember';
// pretend we have ember-data
const FauxDataModel = Ember.ObjectProxy.extend(Ember.PromiseProxyMixin);
function find(data, time) {
return FauxDataModel.create({
promise: new Ember.RSVP.Promise(resolve => {
Ember.run.later(resolve, data, time);
})
});
}
export default Ember.Route.extend({
setupController(controller, model) {
this._super(...arguments);
// no blocking (let it race with the UI)
controller.set('nonBlockingModel', find({ name: 'stef'}, 1000 /* ms */));
},
model() {
// blocking
return find({ name: 'Steve' }, 1000 /* ms */);
}
});
<h1>Welcome to {{appName}}</h1>
<ul>
<li>{{#link-to "index"}}myRoute{{/link-to}}</li>
</ul>
{{outlet}}
{{model.name}}
<br>
{{! you can imagine the following being made more ergomoic}}
<div style="border: 1px solid gray;margin: 1em;padding: 1em;min-height: 50px">
{{! shared shell}}
{{#if nonBlockingModel.isPending}} {{! or if non-ghost parts are to be rendered yet (occlusion/budget)}}
loading...
{{else}}
{{! render non ghost parts}}
{{nonBlockingModel.name}}
{{/if}}
</div>
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.11.1",
"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.11.0",
"ember-data": "2.11.0",
"ember-template-compiler": "2.11.0",
"ember-testing": "2.11.0"
},
"addons": {}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment