ember computed not being updated

40 views Asked by At

i have a computed property in ember

  isCurrentUserLikeIt: Ember.computed('[email protected]_id', function () {
    const userId = parseInt(this.commonService.getId());
    const likestatuses = this.get('likestatuses');

    return likestatuses.filterBy('user_id', userId).get('length') !== 0;
  })

the computed property must be updated when user invoke an action.

this.doSave("likestatus", likestatus).then(function (result) {
        if (result.userlike) {
          const likestatuses = context.get('likestatuses');
          likestatuses.push(likestatusItem);
          context.set('likestatuses', likestatuses);
        } else {
          const likestatuses = context.get('likestatuses').filter(function (item) {
            return item.user_id !== userId
          });
          context.set('likestatuses', likestatuses);
        }

        context.debug(context.get('likestatuses'));
      });

the isCurrentUserLikeIt property is updated when the statement in this.doSave, is in else. but when the statement is in if (result.userlike) the isCurrentUserLikeIt property did not change :(

can anyone solve this

1

There are 1 answers

0
Ember Freak On

In if check, you need to use pushObject instead of push, this is the one will trigger computed property to recalculate and observer to trigger and template to update it to new value.

likestatuses.pushObject(likestatusItem);