Passing equals option to computedFn does not change behaviour
See original GitHub issueI’m trying to pass an options
object to computedFn()
with the equals
property to set the comparer
function to use.
filterForIndividual = computedFn(function(individualsId) {
return this.filter((id, item) => ThObj.value(item, ThIdSessions.INDIVIDUALS_ID) === individualsId);
}, { equals: comparer.structural, });
The problem is that it always uses the comparer.default
comparer. I have set a debug point in mobx.comparer.ts
file and it never enters in the structuralComparer()
method and always use defaultComparer()
.
I have tried to simplify the real code in a CodeSandbox and try to understand what is happening. The problem can be reproduced, no matter what the comparer
value you set, the computedFn()
always runs - so it is not caching - even if the returned data is the same (not same reference).
https://codesandbox.io/s/pedantic-yonath-owtvt?file=/src/App.js
Inspecting the source code seems that computedFn()
can accept an options
object and pass it throught to computed()
, so there must be something I am missing .
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (4 by maintainers)
Of course, you are right, I had this sentence from MobX and completely misunderstood it.
I updated the codesandbox and the re-render only happens using
comparer.identity
as expected.So the problem in my original code must be somewhere else, and the options passed to
computedFn
are working. Thanks for the super fast response.Try:
There is just a single “autorun” in console as opposed to using
t.filterIdentity
(4).