Created
August 17, 2018 00:03
-
-
Save lennyburdette/b6c11a1892a90daff86b9a3d9b6fe177 to your computer and use it in GitHub Desktop.
Ember Concurrency Memoization
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 { task, all } from 'ember-concurrency'; | |
| const delay = ms => new Promise(r => setTimeout(r, ms)); | |
| export default Ember.Component.extend({ | |
| loadFast: task(function*() { | |
| if (!this.loadA.isRunning) { | |
| const a = yield this.loadA.perform(); | |
| } | |
| if (!this.loadB.isRunning) { | |
| this.loadB.perform(); | |
| } | |
| }), | |
| loadSlow: task(function*() { | |
| const tasks = [ | |
| !this.loadA.isRunning && this.loadA.perform(), | |
| !this.loadB.isRunning && this.loadB.perform() | |
| ].filter(Boolean); | |
| yield all(tasks); | |
| }), | |
| loadA: task(function*() { | |
| yield delay(500); | |
| this.set('a', true); | |
| }), | |
| loadB: task(function*() { | |
| yield delay(2000); | |
| this.set('b', true); | |
| }) | |
| }); |
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: 'Ember Twiddle' | |
| }); |
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.15.0", | |
| "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.2.2", | |
| "ember-template-compiler": "3.2.2", | |
| "ember-testing": "3.2.2" | |
| }, | |
| "addons": { | |
| "ember-concurrency": "0.8.19" | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment