Observing nested composited value #3468
-
Given the following snippet inside a class SuperObject {
this.myFields = []
nestedObject = new NestedObject({myNestedFields: this.myFields})
} Alongside an observer component that is rendering I update the super model ( this.myFields = [{"name":"test"}] Which allegedly also changes the inside model's Is this the expected behavior or am I missing something fundamental? Feels to me like an OOTB, regular observation use-case. Should be noted I solved it using the this.fieldsDisposer = reaction(
() => this.myFields,
(myFields) => {
this.nestedObject.setFields(...myFields);
},
);| |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 4 replies
-
Did you check https://mobx.js.org/understanding-reactivity.html and the difference between The object model you are describing is a bit hard to follow, I recommend to create a code sandbox instead to clarify your problem. |
Beta Was this translation helpful? Give feedback.
-
There are no observables. Or observers. We can't advice on what you might
be doing wrong without some code showing what you actually do.
…On Mon, 18 Jul 2022, 10:24 Avivon, ***@***.***> wrote:
Yep, I'm claiming the reaction approach works for me, but I'd rather opt
for a solution without it.
I'll try making it as-pseudo-as-possible cause it can be exemplified in 3
rows:
class SuperObject {
this.myFields = []
nestedObject = new NestedObject({myNestedFields: this.myFields})
this.myFields = [1, 2, 3]}
In this case, observing myNestedFields does not cause a re-render.
—
Reply to this email directly, view it on GitHub
<#3468 (reply in thread)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAN4NBA7T4R7MPRKF2H4DH3VUUPDTANCNFSM532ACJPA>
.
You are receiving this because you commented.Message ID:
***@***.***>
|
Beta Was this translation helpful? Give feedback.
Did you check https://mobx.js.org/understanding-reactivity.html and the difference between
autorun
andreaction
?The object model you are describing is a bit hard to follow, I recommend to create a code sandbox instead to clarify your problem.