Hi all,
We are using Ember 3.4. In the official Ember documentation, it is mentioned that observers should be used sparingly, mainly because they are already heavily used internally in the framework.
I have some doubts about how observers work internally. My understanding is that observers and computed properties are similar in some ways—they are both triggered when dependent properties change. (Yes, I know that computed properties only recompute when they are consumed.)
The main difference I see is:
-
In computed properties, we don’t update other properties;
-
In observers, we often update other properties or perform side effects.
I assume the internal mechanism for triggering both observers and computed properties is similar.
Could someone explain how observers are implemented under the hood and why they are discouraged, while computed properties are recommended? Understanding this will help us find alternative approaches to replace observers safely in our code.
Any insights would be really helpful.
4 posts - 2 participants