Model vs. Promise Comparison


#1

Promises are used very transparently in Ember. Normally you can use a promise just like a model, which is great!

When using comparison however, it gets tricky. When you compare a promise with a model you don’t get a match even if they are equal.

In my case, I have to check if an object is already in an arrays, which sometimes return Promises and sometimes the actual objects. The comparison is done with .contains(). When I do direct comparison with ===, I can try fetching the content property to see if I got a promise and have two checks, which is tedious but it works, with arrays it isn’t so simple anymore.

How did you solve this issue?


#2

What do you mean from “sometimes return Promises and sometimes the actual objects”?


#3

Yes, I should clarify that, sorry.

I’m having a component that does some elaborate selection. Depending on where it is used in the app, it sometimes received a PromiseArray with actual Ember Data Models, and sometimes an Array of Promise objects of the same type of Data Models.

To add another form of equality check, that doesn’t work with Promises: Ember.isEqual.


#4

I think you should handle this in upper layer. It’s better component deals with one type of input


#5

Thanks, I figured that might be the only solutions. I just hoped, that since Promises are so transparent that there would be a more elegant solution to this.