Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ember.computed.equal returns false on identical strings

Is there something I don't understand or have I encountered a bug?

isCreator: Ember.computed.equal('session.user.id', 'model.user.id'), //false
isCreator2: Ember.computed('session.user.id','model.user.id', function() {  //true
    return this.get('session.user.id') === this.get('model.user.id');
}),
like image 964
Martin Malinda Avatar asked Sep 06 '15 11:09

Martin Malinda


2 Answers

Ember.computed.equal doesn't take two property keys, it takes one property key and one constant value. Taken from the documentation:

A computed property that returns true if the provided dependent property is equal to the given value.

If you want to compare two different properties you'll have to write the computed property manually like you've done with idCreator2.

like image 106
GJK Avatar answered Nov 16 '22 09:11

GJK


You can use ember-awesome-macro's equal instead, which takes two property keys. See https://github.com/kellyselden/ember-awesome-macros#equal.

like image 43
Gus Koumarelas Avatar answered Nov 16 '22 07:11

Gus Koumarelas