Skip to content

[3.1.0-beta.5] notifyPropertyChange() fails for plain objects #16427

Closed

Description

@kanongil

This unit test will fail on the latest beta:

test('notifies computed properties on plain objects', function (assert) {
  let obj = {
    a: 45,
    b: computed(function () {
      return ~~(this.a / 10);
    })
  };

  assert.equal(get(obj, 'b'), 4);

  obj.a = 10;
  Ember.notifyPropertyChange(obj, 'b');

  assert.equal(get(obj, 'b'), 1);      // fails - returned value is still 4
});

It works, as intended, if I do the same on an ember object.

Activity

  1. mmun commented on Mar 27, 2018

    @mmun
    Member

    I assume you mean computed('a', function(){ ... })?

  2. kanongil commented on Mar 27, 2018

    @kanongil
    ContributorAuthor

    No, the code is as intended. Obviously, this is not what failed for me, but a reduced test case to expose the issue.

  3. mmun commented on Mar 27, 2018

    @mmun
    Member

    This is working as intended then. Since b has no dependency on a, notifying a will not cause b to be invalidated.

    Did you mean Ember.notifyPropertyChange(obj, 'b');?

  4. kanongil commented on Mar 27, 2018

    @kanongil
    ContributorAuthor

    Ah, so I did make an error. Yes Ember.notifyPropertyChange(obj, 'b'); is the proper failing case.

    Sorry about that. I have updated the original post.

  5. kanongil commented on Mar 28, 2018

    @kanongil
    ContributorAuthor

    A bit of further investigation reveals that this usage is scheduled for deprecation, that it also fails on canary, and that it works correctly if I use Ember.defineProperty(obj, 'b', …) to define the computed value.

  6. mmun commented on Mar 28, 2018

    @mmun
    Member

    Yeah, but we still need to make it work for backwards compatibility. The fix should be relatively easy but I haven't had time to work on it.

  7. added this to the v3.1.x milestone on Apr 21, 2018
  8. self-assigned this
    on Apr 21, 2018
  9. added 6 commits that reference this issue on May 17, 2018
    bba66f9
    8a3947d
    26ea077
    c486d7a
    f73e377
    166d395
  10. added a commit that references this issue on Jul 13, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions