Skip to content

Instantly share code, notes, and snippets.

@alexdiliberto
Last active March 21, 2017 22:15
Show Gist options
  • Select an option

  • Save alexdiliberto/110d60266f6b98a4fc20f8ee7aab3eef to your computer and use it in GitHub Desktop.

Select an option

Save alexdiliberto/110d60266f6b98a4fc20f8ee7aab3eef to your computer and use it in GitHub Desktop.
Architecture: Nested Loading Routes
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'Ember Twiddle'
});
import Ember from 'ember';
import config from './config/environment';
const Router = Ember.Router.extend({
location: 'none',
rootURL: config.rootURL
});
Router.map(function() {
this.route('foo', function() {
this.route('bar', function() {
this.route('woot');
});
});
});
export default Router;
import Ember from 'ember';
export default Ember.Route.extend({
model: function() {
return new Ember.RSVP.Promise(function(resolve) {
Ember.run.later(null, resolve, {}, 1000);
});
}
});
import Ember from 'ember';
export default Ember.Route.extend({
model: function() {
return new Ember.RSVP.Promise(function(resolve) {
Ember.run.later(null, resolve, {}, 1000);
});
}
});
import Ember from 'ember';
export default Ember.Route.extend({
model: function() {
return new Ember.RSVP.Promise(function(resolve) {
Ember.run.later(null, resolve, {}, 1000);
});
}
});
body {
margin: 12px 16px;
font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
font-size: 12pt;
}
<h2>Loading substates</h2>
<p>
See <a href="http://discuss.emberjs.com/t/proposal-nested-loading-routes/2895">here</a> for a more full description of what's being demoed.
</p>
<p>
This demonstrates the "waterfall"
of loading substates, whereby
if slow model promises are encountered
(slow === takes longer than than a
run loop turn to resolve), a loading
event will be fired on that route.
The default loading handler will
look for an appropriately named
nested loading route/template. In
this example, nested loading templates
are provided for each nested route
is being slowly entered (due to each
nested route returning a slow
promise from the `model` hook).
</p>
<p>
Try removing/renaming the loading
templates to get a better idea of
how the loading waterfall behavior
changes.
</p>
<p>
{{#link-to 'index'}}index{{/link-to}}
{{#link-to 'foo.bar.woot'}}foo/bar/woot{{/link-to}}
</p>
<div class="outlet-container">{{outlet}}</div>
<h2>Bar</h2>
<div class="outlet-container">{{outlet}}</div>
<h3>Loading child of bar</h3>
<h2>Foo</h2>
<div class="outlet-container">{{outlet}}</div>
<h3>Loading child of foo</h3>
<h3>Loading child of application</h3>
{
"version": "0.12.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.12.0",
"ember-template-compiler": "2.12.0",
"ember-testing": "2.12.0"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment