Skip to content

Instantly share code, notes, and snippets.

@poulet42
Forked from sglanzer-deprecated/router.js
Last active February 1, 2023 11:57
Show Gist options
  • Save poulet42/93932b9b0f64d00f60794dd008efd3e2 to your computer and use it in GitHub Desktop.
Save poulet42/93932b9b0f64d00f60794dd008efd3e2 to your computer and use it in GitHub Desktop.
Sync and async routing
import Ember from 'ember';
import config from './config/environment';
const Router = Ember.Router.extend({
location: 'none',
rootURL: config.rootURL
});
Router.map(function() {
this.route('parent', function() {
this.route('child');
})
this.route('async')
});
export default Router;
import Ember from 'ember';
export default Ember.Route.extend({
});
import Ember from 'ember';
export default Ember.Route.extend({
model() {
return {
msg: new Ember.RSVP.Promise(
function(resolve, reject) {
Ember.run.later(function() {
resolve('Async promise');
}, 5000);
}
)
}
},
setupController(controller, model) {
this._super(controller, model)
controller.set('msg', null)
model.msg.then(result => {
controller.set('msg', result)
})
}
});
import Ember from 'ember';
export default Ember.Route.extend({
model() {
return new Ember.RSVP.Promise(
function(resolve) {
Ember.run.later(function() {
resolve({ msg: 'Sync promise' });
}, 5000);
}
)
}
});
{{#link-to 'sync'}}Sync{{/link-to}}
{{#link-to 'async'}}Async{{/link-to}}
{{outlet}}
<div>Part of the async template</div>
<div>The template as a whole is displayed immediately</div>
{{#if msg}}
<div>The resolved promise: {{msg}}</div>
{{else}}
<div>Loading async msg in 5 seconds...</div>
{{/if}}
<div>This is a loading template for sync transition</div>
<div>The promise will resolve in 5 seconds, completing the transition</div>
<div>Part of the sync template</div>
<div>The whole template is delayed until the transition completes</div>
<div>The resolved promise: {{model.msg}}</div>
{
"version": "0.10.4",
"EmberENV": {
"FEATURES": {}
},
"options": {
"use_pods": false,
"enable-testing": false
},
"dependencies": {
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js",
"ember": "4.7.0",
"ember-template-compiler": "4.7.0"
},
"addons": {
"ember-data": "4.7.0"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment