Replies: 2 comments 5 replies
-
I don't fully grasp what is wrong with using a computed in your case. Would
you mind explaining in some more detail with a concrete (slimmed down)
example what you are trying to achieve? What do you mean by "don't want to
trigger reactivity on the whole thing"?
…On Thu, Mar 21, 2024 at 11:26 AM Manuel ***@***.***> wrote:
Hey there :)
I like observable arrays and would want to be able to create one in a way
that it auto-updates when dependencies change.
function useBlocks(id) {
return observableArrayFrom(() => {
return dependOnSomethingAndReturnArray()
})}
I felt it's a computed value, but I don't want to trigger reactivity on
the whole thing when calling .get(), only when accessing e.g. length or
specific entries.
I've started with something like this:
const compu = computed(() => {
return [...]})let arrautorun(() => {
const result = compu.get()
if (!arr) arr = observable.array(result)
else arr.replace(result)})return arr
but:
- I can't arr.replace outside of an action
- if this is run inside a transaction, the autorun will not run until
the end of the transaction
- I'm not sure if mobx would still ensure correct order of updates, as
it's not exactly a classic "computation" anymore
So I ended up with these frankenstein functions:
- autorunButAlsoImmediately
***@***.***/core/src/mobx/mobx-utils.ts#L288>
- observableArrayMap
***@***.***/core/src/mobx/mobx-utils.ts#L100>
I'm writing here because my request seems reasonable but my solution not
at all 😅
I'm hoping that I'm missing an obvious thing that makes this all
unnecessary, because while this seems to work, it has already brought up
many edge cases & disposal weirdnesses that I would wish to not engage with
😅
—
Reply to this email directly, view it on GitHub
<#3847>, or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAN4NBFWAAACPEQIVZKMDBTYZKYUDAVCNFSM6AAAAABFBFA7YGVHI2DSMVQWIX3LMV43ERDJONRXK43TNFXW4OZWGQYDGNBYHE>
.
You are receiving this because you are subscribed to this thread.Message
ID: ***@***.***>
|
Beta Was this translation helpful? Give feedback.
3 replies
-
Would you mind writing some (pseudo) code of what you are trying to
achieve. It's easy to misunderstand the case in the abstract.
…On Thu, Mar 21, 2024 at 12:20 PM Manuel ***@***.***> wrote:
Thanks for diving in so quickly!
My Question is not so much about the array part, but how to make the array
track/auto update based on the result of a computation. (So like an autorun
that does not wait for the current transaction to finish because it's
actually a comoutation that no-one *directly* depends on - only on the
resulting array/map/set 🤔)
And I think you might've missed the second part of my last comment because
of my bad formatting 😅:
if I were to use computed, the places where I .get() will react on any
dependency changes of the computed, but what I would want is to observe
e.g. the map key (in case of ObservableMap) changes, and only update if
that map key changed, not if the computation that produced the map changed.
🤔
Maybe I'm misunderstanding something here 😅🫣
—
Reply to this email directly, view it on GitHub
<#3847 (reply in thread)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAN4NBAYMTYYS3XY2WPA2NDYZK66ZAVCNFSM6AAAAABFBFA7YGVHI2DSMVQWIX3LMV43SRDJONRXK43TNFXW4Q3PNVWWK3TUHM4DQNRUGQ2TG>
.
You are receiving this because you commented.Message ID:
***@***.***>
|
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hey there :)
I like observable arrays and would want to be able to create one in a way that it auto-updates when dependencies change.
I felt it's a computed value, but I don't want to trigger reactivity on the whole thing when calling
.get()
, only when accessing e.g.length
or specific entries.I've started with something like this:
but:
So I ended up with these frankenstein functions:
autorunButAlsoImmediately
observableArrayMap
I'm writing here because my request seems reasonable but my solution not at all 😅
I'm hoping that I'm missing an obvious thing that makes this all unnecessary, because while this seems to work, it has already brought up many edge cases & disposal weirdnesses that I would wish to not engage with 😅
Beta Was this translation helpful? Give feedback.
All reactions