Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I create a promise in Ember.js for an Ember-data model

I have an Ember-Data model. I would like to do some processing in the .then promise once it has loaded and then return the same model as a promise. This is what I have right now. How do I wrap up the return object as a promise so that other promises can be chained?

App.Member.find(1).then(function(member){

  //do some processing here
  return member; // Does this need to be wrapped as a promise?

} 
like image 766
ianpetzer Avatar asked Jul 04 '13 17:07

ianpetzer


1 Answers

Basically you can create a promise like this:

var promise = new Ember.RSVP.Promise(function(resolve, reject){
  // succeed
  resolve(value);
  // or reject
  reject(error);
});

and then you can use the then property to chain it further:

promise.then(function(value) {
  // success
}, function(value) {
  // failure
});

You can aslo have a look at this jsbin which shows how they could be implemented. And this is also very helpful.

Hope it helps.

like image 164
intuitivepixel Avatar answered Oct 04 '22 15:10

intuitivepixel