Replies: 1 comment 10 replies
-
|
Hey @BrianHung - thanks for the detailed walkthrough. Can you say more about what an ideal solution looks like? Do you want to be able to say, pass some kind of flag to a view to change its comparison behavior? Add some new wrapper or type of What would make MST feel more ergonomic for this use case? |
Beta Was this translation helpful? Give feedback.
10 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I have an array of cell references that are computed in the views prop of a row. Right now, anytime that a new cell is created (and added to a row), because cells are added to a global cells map, the views prop of all rows is recomputed.
And as a result, all other dependents of
row.cellsare also recomputed as well.Is it possible to use
comparer.shallowor custom equals function in views to return the same array of cell references if it is the same?For example, in the codesandbox, adding a cell to the second row should not affect the cells of the first row.
https://codesandbox.io/s/mobx-state-tree-table-mx37kj?file=/models/Row.js
Trying to dig into mobx-state-tree source code:
mobx-state-tree/packages/mobx-state-tree/src/types/complex-types/model.ts
Line 493 in 0c07dd4
Noticing that getters defined in views are annotated using mobx
computed. In the use case above, we are exactly looking forcomputed.structinstead: https://mobx.js.org/computeds.html#computed-structThis is because, while the keys of a
cellscan change, a row may have the samecellsarray structurally due to filter.The following seems to work by using
rawMobX: https://codesandbox.io/s/mobx-state-tree-table-forked-xz0zkc?file=/models/Row.js:151-1123Would like a cleaner solution though as this seems pretty messy.
Beta Was this translation helpful? Give feedback.
All reactions