Ember.js Observer on computed property, not working. Example from guides

corsen

I am learning Ember.js and going through some of the guides. I was reading about observers here: http://emberjs.com/guides/object-model/observers/

I wanted to play around with the example so I copied and pasted it into my js file. After adding an alert statement to the observer callback, I was surprised to find it was not invoked.

http://jsbin.com/UWEseSo/2/edit?js,output

I was able to find that if you add:

person.get('fullName');

Before the call to set the firstName, the observer callback will be invoked. If I set the first name again immediately after the callback would again not be invoked.

Can anyone explain what is going on here?

Thank you.

EDIT-------

I've traced through the code a little more and I now I have an idea on why this behavior may be like this. Although the example seems like there is a bug it may just be an optimization. I observed earlier that if I called "get" the observer would work. If I did not call "get" the observer would not work. I believe Ember.js may just being smart about this and intentionally not bothering to invoke the observer if no "get" was called. They may be doing this because if there was no "get" there is no reason to invoke the observer because the application can not possibly be showing out of date information.

Once "get" is called an internal flag is set to ensure the observer will be invoked on the next "set".

intuitivepixel

It looks like you got the explanation right for this behaviour all by yourself, and to confirm your assumptions there is indeed a change that was introduced in rc8 for performance reason mainly.

You can read here the full article on that, under UNCONSUMED COMPUTED PROPERTIES DO NOT TRIGGER OBSERVERS

This means basically that if you need to observe a computed property but aren't currently retrieving it, just get it in your init method.

Hope it helps.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Ember.js: Computed property on current element in array

From Dev

Ember.js checkbox for array controller computed property

From Dev

Ember computed property not being updated

From Dev

Ember.js binding to computed property in Ember.Object from controller doesn't work

From Dev

Ember.js: Trigger 'Ember.computed.filter' to update when a property changes in the controller

From Dev

How can I do an Ember.js computed property on an Ember Data model based on an async relationship?

From Dev

Computed Property Macros with Ember CLI

From Dev

Ember - computed property not firing/updating

From Dev

Ember.js computed property filter hasMany array

From Dev

ember.js Access each context in computed property

From Dev

Ember.js isDestroyed observer not working

From Dev

Ember computed property for object attribute

From Dev

Why does this example from the Ember.js guides not work?

From Dev

Retrieving computed property from controller in ember.js

From Dev

Ember computed property _super

From Dev

How do you create a computed property in Ember.js to see if a single Ember Data attribute is dirty?

From Dev

Ember computed property or observer within a service

From Dev

Ember Computed Property vs Ember Observer

From Dev

Ember.js Computed Property vs Observer vs didReceiveAttrs() in a Component

From Dev

Computed properties example in ember.js fails

From Dev

Ember.js Observer on computed property, not working. Example from guides

From Dev

Why does this Ember.computed property's observer fire twice?

From Dev

Ember.js: Trigger 'Ember.computed.filter' to update when a property changes in the controller

From Dev

EmberJS: Observer Not Being Triggered on Computed Property

From Dev

Ember.js: How do I prevent this property observer from being hit more than once?

From Dev

Ember computed property for object attribute

From Dev

Ember.js: Computed property from child models

From Dev

ember js - value returned from computed property looks cached

From Dev

Ember unit test computed property with then

Related Related

  1. 1

    Ember.js: Computed property on current element in array

  2. 2

    Ember.js checkbox for array controller computed property

  3. 3

    Ember computed property not being updated

  4. 4

    Ember.js binding to computed property in Ember.Object from controller doesn't work

  5. 5

    Ember.js: Trigger 'Ember.computed.filter' to update when a property changes in the controller

  6. 6

    How can I do an Ember.js computed property on an Ember Data model based on an async relationship?

  7. 7

    Computed Property Macros with Ember CLI

  8. 8

    Ember - computed property not firing/updating

  9. 9

    Ember.js computed property filter hasMany array

  10. 10

    ember.js Access each context in computed property

  11. 11

    Ember.js isDestroyed observer not working

  12. 12

    Ember computed property for object attribute

  13. 13

    Why does this example from the Ember.js guides not work?

  14. 14

    Retrieving computed property from controller in ember.js

  15. 15

    Ember computed property _super

  16. 16

    How do you create a computed property in Ember.js to see if a single Ember Data attribute is dirty?

  17. 17

    Ember computed property or observer within a service

  18. 18

    Ember Computed Property vs Ember Observer

  19. 19

    Ember.js Computed Property vs Observer vs didReceiveAttrs() in a Component

  20. 20

    Computed properties example in ember.js fails

  21. 21

    Ember.js Observer on computed property, not working. Example from guides

  22. 22

    Why does this Ember.computed property's observer fire twice?

  23. 23

    Ember.js: Trigger 'Ember.computed.filter' to update when a property changes in the controller

  24. 24

    EmberJS: Observer Not Being Triggered on Computed Property

  25. 25

    Ember.js: How do I prevent this property observer from being hit more than once?

  26. 26

    Ember computed property for object attribute

  27. 27

    Ember.js: Computed property from child models

  28. 28

    ember js - value returned from computed property looks cached

  29. 29

    Ember unit test computed property with then

HotTag

Archive