Last active
March 29, 2017 09:20
-
-
Save fhrbek/1200d513e553975db6193a3016d2b683 to your computer and use it in GitHub Desktop.
Slow Route with loading event
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Ember from 'ember'; | |
export default Ember.Controller.extend({ | |
appName: 'Randomly Slow Route Demo' | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Ember from 'ember'; | |
export default Ember.Controller.extend({ | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Ember from 'ember'; | |
import config from './config/environment'; | |
const Router = Ember.Router.extend({ | |
location: 'none', | |
rootURL: config.rootURL | |
}); | |
Router.map(function() { | |
this.route('slow-route', {path: '/'}); | |
}); | |
export default Router; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Ember from 'ember'; | |
const API = [ | |
{ | |
data: [1, 2, 3], | |
responseTime: 100 | |
}, { | |
data: [100, 200, 300], | |
responseTime: 1000 | |
}, { | |
data: [1000, 2000, 3000], | |
responseTime: 500 | |
}]; | |
export default Ember.Route.extend({ | |
dataVersion: 0, | |
model() { | |
return new Promise((resolve, reject) => { | |
let dataVersion = this.get('dataVersion'); | |
console.log('REFRESH DATA WITH VERSION', dataVersion, ' (IT WILL TAKE', API[dataVersion].responseTime, 'ms)'); | |
Ember.run.later(function () { | |
let data = API[dataVersion].data; | |
console.log('DATA VERSION', dataVersion, 'RETRIEVED: ', data); | |
resolve(data); | |
}, API[dataVersion].responseTime); | |
}); | |
}, | |
setupController(controller, model) { | |
console.log('SETUP CONTROLLER WITH DATA', model); | |
this._super(controller, model); | |
}, | |
actions: { | |
loading(transition, route) { | |
console.log('LOADING STARTED (', transition.sequence, ')', route.routeName); | |
this.controllerFor(route.routeName).set('_loading', true); | |
this.set('_loadingSequence', transition.sequence); | |
transition.finally(() => { | |
console.log('LOADING FINISHED (', transition.sequence, ')'); | |
if (this.get('_loadingSequence') === transition.sequence) { | |
console.log('PAGE LOADED (all remaining transitions will be ignored)'); | |
this.controllerFor(route.routeName).set('_loading', false); | |
} | |
}); | |
}, | |
refresh() { | |
this.set('dataVersion', 1); | |
this.refresh(); | |
Ember.run.later(() => { | |
this.set('dataVersion', 2); | |
this.refresh(); | |
}, 100); | |
} | |
} | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"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.12.0", | |
"ember-template-compiler": "2.12.0", | |
"ember-testing": "2.12.0" | |
}, | |
"addons": { | |
"ember-data": "2.12.1" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment