-
-
Save villander/4efe817975d4c85c1eb75e0a476bc691 to your computer and use it in GitHub Desktop.
PromiseProxyMixin UI feedback
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 { makeTestPromise } from '../utils/test-foo'; | |
| const TestFoo = Ember.Object.extend(Ember.PromiseProxyMixin, { | |
| init() { | |
| // By default a PromiseProxy will rethrow a | |
| // rejected promise causing it to be left | |
| // unhandled. Since by the nature of this use | |
| // pattern it is handled (see template) we add | |
| // a no-op to the end of the chain and the | |
| // rejection will be concidered handled. | |
| this.catch(() => {}); | |
| } | |
| }); | |
| export default Ember.Controller.extend({ | |
| appName: 'Ember Twiddle', | |
| actions: { | |
| test() { | |
| const promise = makeTestPromise(); | |
| this.set('foo', TestFoo.create({promise})); | |
| } | |
| } | |
| }); |
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
| body { | |
| margin: 12px 16px; | |
| font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; | |
| font-size: 12pt; | |
| } | |
| .info { | |
| color: lightblue; | |
| } | |
| .success { | |
| color: green; | |
| } | |
| .danger { | |
| color: red; | |
| } |
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.8.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.5.1", | |
| "ember-data": "2.5.2", | |
| "ember-template-compiler": "2.5.1" | |
| } | |
| } |
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 function rand(min, max) { | |
| return Math.floor(Math.random() * (max - min) + min); | |
| } | |
| export function makeTestPromise() { | |
| return new Ember.RSVP.Promise((resolve, reject) => { | |
| const time = rand(500, 2000); | |
| const willResolve = rand(1, 100) % 2 === 0; | |
| Ember.run.later(() => { | |
| if (willResolve) { | |
| resolve('Works'); | |
| } else { | |
| reject(new Error('Failed!')); | |
| } | |
| }, time); | |
| }, 'TestPromise'); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment