Skip to content

Instantly share code, notes, and snippets.

@NullVoxPopuli
Last active June 10, 2019 02:49
Show Gist options
  • Save NullVoxPopuli/e124d60e6a5581f98c2e129b7f637ec2 to your computer and use it in GitHub Desktop.
Save NullVoxPopuli/e124d60e6a5581f98c2e129b7f637ec2 to your computer and use it in GitHub Desktop.
Demonstrate Loading and Error Substates
import Controller from '@ember/controller';
import { inject as service } from '@ember/service';
import { reads } from '@ember/object/computed';
export default class ApplicationController extends Controller {
router = service('router');
current = reads('router.currentRouteName');
}
import EmberRouter from '@ember/routing/router';
import config from './config/environment';
const Router = EmberRouter.extend({
location: 'none',
rootURL: config.rootURL
});
Router.map(function() {
this.route('sub-route-a');
});
export default Router;
import Route from '@ember/routing/route';
export default class AppRoute extends Route {
actions = {
loading(transition, originRoute) {
return true; // allows the loading template to be shown
},
error(error, transition) {
return true;
}
}
}
import Route from '@ember/routing/route';
export default class AppRoute extends Route {
async model() {
await new Promise((resolve, reject) => {
setTimeout(
() => reject(new Error('ya')),
5000
);
});
}
}
import Route from '@ember/routing/route';
export default class SubRouteA extends Route {
async model() {
await new Promise((resolve, reject) => {
setTimeout(
() => reject(new Error('ya')),
5000
);
});
}
}
<h1>Welcome to {{this.appName}}</h1>
<br>
Current: {{this.current}}
<br>
{{outlet}}
<br>
<br>
{{#link-to 'sub-route-a'}}
Sub Route A
{{/link-to}}
what ever goes here
{{this.model}}
{
"version": "0.15.1",
"EmberENV": {
"FEATURES": {}
},
"options": {
"use_pods": false,
"enable-testing": false
},
"dependencies": {
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.js",
"ember": "3.4.3",
"ember-template-compiler": "3.4.3",
"ember-testing": "3.4.3"
},
"addons": {
"ember-data": "3.4.2"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment