Skip to content

Observer on computed property is firing when the computed value is unchanged #774

Closed

Description

@adamlogic

Here is a jsfiddle to demonstrate the issue: http://jsfiddle.net/NfEgM/3/

When "set" is called on the "prop" property, the observer only fires if it is set with a new value. This is expected behavior.

The "computedProp" observer is firing every time, though, even when the computed value is the same. I believe this is unexpected behavior. The value is being recalculated because one of it's dependencies changes, but I think the observer should only fire if the actual value changes.

Is this a bug or intended behavior?

Activity

  1. wagenet commented on May 2, 2012

    @wagenet
    Member

    @adamlogic There's no way around it. We don't compute CPs until get is called, which happens after the observer is fired. If we checked right away, we'd have to compute much more frequently and performance would suffer.

  2. adamlogic commented on May 2, 2012

    @adamlogic
    Author

    @wagenet Understood. Would you be open to a docs patch that clarifies this behavior?

  3. wagenet commented on May 2, 2012

    @wagenet
    Member

    @adamlogic Certainly. It would definitely be worth highlighting the fact that CPs are lazily computed. It's totally worth it, but sometimes it catches people by surprise, especially if they are trying to use CPs when they should use observers.

  4. adamlogic commented on May 3, 2012

    @adamlogic
    Author

    @wagenet Added a pull request. Curious if you have any examples handy of people using CPs when they should use observers.

  5. wagenet commented on May 3, 2012

    @wagenet
    Member

    I once saw someone trying to do responsive style behavior in a CP, definitely an odd idea. The main thing you'll notice is that observers fire instantly, whereas bindings wait until the end of the runloop and CPs don't fire until requested.

  6. added a commit that references this issue on May 3, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions