Skip to content

Instantly share code, notes, and snippets.

@givanse
Last active October 27, 2017 20:44
Show Gist options
  • Save givanse/c9adfd83acffe5e78624482933b54730 to your computer and use it in GitHub Desktop.
Save givanse/c9adfd83acffe5e78624482933b54730 to your computer and use it in GitHub Desktop.
never un-render
import Ember from 'ember';
export default Ember.Component.extend({
classNames: ['rich-and-complex']
});
import Ember from 'ember';
export default Ember.Controller.extend({
});
import Ember from 'ember';
import config from './config/environment';
const Router = Ember.Router.extend({
location: 'none',
rootURL: config.rootURL
});
Router.map(function() {
// rich & complex model
this.route('heavy-dom', {path: '/heavy-dom/:rc_model'}, function() {
// guest model
this.route('guest', {path: '/guest/:g_model'});
this.route('expensive-a');
this.route('expensive-b');
});
this.route('just-a-page');
});
export default Router;
import Ember from 'ember';
export default Ember.Route.extend({
});
import Ember from 'ember';
export default Ember.Route.extend({
model() {
const model = {
name: 'A',
};
this.transitionTo('heavy-dom', model);
},
});
import Ember from 'ember';
export default Ember.Route.extend({
model() {
return 'B';
}
});
import Ember from 'ember';
export default Ember.Route.extend({
//renderTemplate docs:
//https://emberjs.com/api/ember/2.16/classes/Route/methods/renderTemplate?anchor=renderTemplate
renderTemplate(controller, model) {
this._super(...arguments);
if (!model._templateName) {
return;
}
//render docs:
//https://emberjs.com/api/ember/2.16/classes/Route/methods/render?anchor=render
this.render(model._templateName, {
model: model,
});
},
//TODO: this hook is executed twice :(
serialize(model) {
console.info('serialize /heavy-dom/guest/');
console.info(model);
//NOTE:
//results in a URL that is useless to share
return {
g_model: 'g_model'
};
},
});
import Ember from 'ember';
export default Ember.Route.extend({
//TODO: this hook is executed twice :(
serialize(model) {
console.info('serialize /heavy-dom');
console.info(model);
//NOTE:
//results in a URL that is useless to share
return {
rc_model: 'rc_model'
};
},
});
import Ember from 'ember';
export default Ember.Route.extend({
redirect() {
this.transitionTo('just-a-page');
}
});
import Ember from 'ember';
export default Ember.Route.extend({
model() {
const hostModel = Promise.resolve({
_templateName: 'just-a-page',
title: "just a title",
});
const heavyDomModel = null;
this.transitionTo('heavy-dom.guest', heavyDomModel, hostModel);
},
});
body {
margin: 12px 16px;
font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
font-size: 12pt;
}
.rich-and-complex {
border-radius: 4px;
background-color: #f3b500;
border: 1px solid yellow;
padding: 7px;
width: 300px;
height: 100px;
text-align: center;
}
{{link-to "Home" "just-a-page"}}
{{link-to "Heavy A" "heavy-dom.expensive-a"}}
{{link-to "Heavy B" "heavy-dom.expensive-b"}}
{{link-to "Guest" "heavy-dom.guest" "dummy"}}
<br><br>
{{outlet}}
heavy-dom/guest.hbs
<br>
{{model}}
<br>
<b>never be rendered</b>, if you don't link to it of course
<div id="wrapper-for-debug-purposes-only">
{{rich-and-complex name=model.name}}
</div>
{{outlet}}
<h5>{{model.title}}</h5>
Click the links to render a rich, complex & flavorful component.
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.12.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.4.5",
"ember-template-compiler": "2.4.5",
"ember-testing": "2.4.5"
},
"addons": {}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment