Structural equality
If the return value of a computed property is a primitive, it is easy to know when there is a new value. MobX compares the previous value of the computed property with the newly evaluated value and then fires notifications if they differ. Thus, value comparisons become important to ensure notifications are fired only on a real change.
For objects, this is not straightforward. The default comparison is done based on reference checks (using the === operator). This treats the objects as being different even though the values within them are exactly the same.
In the following example, the metrics computed property generates a new object every time the start or end properties change. Since the autorun (defined in the constructor) ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access