-
-
Save MichalBryxi/4b968f07013d18b64d50bf583817d616 to your computer and use it in GitHub Desktop.
Slow Route with loading state
This file contains 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 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 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 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.Route.extend({ | |
actions: { | |
refresh() { | |
let realController = this.controllerFor('slow-route'); | |
console.log('REFRESH CALLED IN THE LOADING ROUTE', realController.get('_route')); | |
realController.get('_route')._refresh(); | |
} | |
} | |
}); |
This file contains 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: 5000 | |
}, { | |
data: [100, 200, 300], | |
responseTime: 10000 | |
}, { | |
data: [1000, 2000, 3000], | |
responseTime: 5000 | |
}]; | |
export default Ember.Route.extend({ | |
dataVersion: 0, | |
beforeModel(transition) { | |
let controller = this.controllerFor(transition.targetName); | |
controller.set('_route', this); | |
console.log('LOADING STARTED (', transition, ') '); | |
}, | |
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); | |
}, | |
_refresh() { | |
this.set('dataVersion', 1); | |
this.refresh(); | |
Ember.run.later(() => { | |
this.set('dataVersion', 2); | |
this.refresh(); | |
}, 100); | |
}, | |
actions: { | |
refresh() { | |
this._refresh(); | |
} | |
} | |
}); |
This file contains 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