Skip to content

Instantly share code, notes, and snippets.

@k-fish
Created January 24, 2017 12:38
Show Gist options
  • Save k-fish/e32e0f747742de63c2fd0aead2e529f5 to your computer and use it in GitHub Desktop.
Save k-fish/e32e0f747742de63c2fd0aead2e529f5 to your computer and use it in GitHub Desktop.
Nested Promise Resolve
import Ember from 'ember';
const { RSVP } = Ember;
export default Ember.Controller.extend({
appName: 'Ember Twiddle',
singlePromise() {
return RSVP.resolve('banana');
},
nestedPromise(otherPromise) {
return RSVP.resolve(otherPromise);
},
actions: {
clickedSinglePromise() {
this.singlePromise().then(result => this.set('result', result));
},
clickedNestedPromise() {
const singlePromise = this.singlePromise();
this.nestedPromise(singlePromise).then(result => this.set('result', result));
}
}
});
<h1>Welcome to {{appName}}</h1>
<br>
<br>
{{outlet}}
<br>
<br>
<button {{action 'clickedSinglePromise'}}> Single Promise </button>
<button {{action 'clickedNestedPromise'}}> Nested Promise </button>
<br>
Result: {{result}}
{
"version": "0.11.0",
"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.10.2",
"ember-data": "2.11.0",
"ember-template-compiler": "2.10.2",
"ember-testing": "2.10.2"
},
"addons": {}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment