Last active
March 28, 2017 09:10
-
-
Save fhrbek/6b965f0c3b6c6d56b93b065fbeff039a to your computer and use it in GitHub Desktop.
Slow Route
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'; | |
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: { | |
refresh() { | |
this.set('dataVersion', 1); | |
this.refresh(); | |
Ember.run.later(() => { | |
this.set('dataVersion', 2); | |
this.refresh(); | |
}, 100); | |
} | |
} | |
}); |
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