Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
adamlogic opened this issue May 2, 2012 · 5 comments

Comments

@adamlogic
Copy link

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?

@wagenet
Copy link
Member

wagenet commented May 2, 2012

@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.

@wagenet wagenet closed this as completed May 2, 2012
@adamlogic
Copy link
Author

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

@wagenet
Copy link
Member

wagenet commented May 2, 2012

@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.

@adamlogic
Copy link
Author

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

@wagenet
Copy link
Member

wagenet commented May 3, 2012

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.

adamlogic pushed a commit to adamlogic/ember.js that referenced this issue May 3, 2012
wagenet added a commit that referenced this issue May 3, 2012
add docs regarding observers and computed properties (ref #774)
kategengler added a commit that referenced this issue Feb 2, 2024
the removal of the implicit loading of a model per RFC #774

Co-authored-by: Aaron Chambers <aaron.chambers@hey.com>
kategengler added a commit that referenced this issue Feb 2, 2024
…opting into

the removal of the implicit loading of a model per RFC #774

Co-authored-by: Aaron Chambers <aaron.chambers@hey.com>
kategengler added a commit that referenced this issue Feb 2, 2024
…ature

[FEATURE] Add an optional feature "no-implicit-route-model" to allow the removal of the implicit loading of a model per RFC #774
kategengler added a commit that referenced this issue Feb 20, 2024
…opting into

the removal of the implicit loading of a model per RFC #774

Co-authored-by: Aaron Chambers <aaron.chambers@hey.com>
(cherry picked from commit e46ac3a)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants