-
Hey, we're currently using mobx versions like this https://codesandbox.io/s/zealous-volhard-20zt1?file=/src/App.tsx. Should assigning regular object to a proxied observable It seems like in this example, the assigned value has lost its observability (observerness)? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 5 replies
-
If you assign non-observable plain object to observable object, it's automatically copied and converted to observable. |
Beta Was this translation helpful? Give feedback.
-
It sounds like your currentModelInstance field itself is not marked as
observable, or that reference is being read by a component that is not an
observer.
…On Thu, Apr 8, 2021 at 5:45 PM Zach Wegrzyniak ***@***.***> wrote:
I think you are now debugging differences between console.debug
implementations, not differences in MobX?
It was an errant browserslist setting in the package.json containing IE 11
support. My mistake. The proxy is logging as expected now.
@mweststrate <https://github.com/mweststrate> thanks for pointing us
toward isObservableObject, hadn't seen that yet.
A little bit more context is we have a relatively deeply nested object
coming back from https://github.com/rjsf-team/react-jsonschema-form.
diff --git a/file.tsx b/file.tsx--- a/file.tsx+++ b/file.tsx
const onChange = useCallback(
(val: any) => {
tweakOnChange?.({ value: val, schema })- modelStore.currentModelInstance = val+ Object.assign(modelStore.currentModelInstance, val)
},
[modelStore, schema, tweakOnChange]
)
Without the Object.assign, assigning the variable val (which isn't
observable), doesn't seem to trigger an update.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#2879 (reply in thread)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAN4NBGW73HLAOTYXQ7ZPMLTHXMUHANCNFSM42TAQ5LA>
.
|
Beta Was this translation helpful? Give feedback.
If you assign non-observable plain object to observable object, it's automatically copied and converted to observable.
store.foo = { x: 1 }
is same asstore.foo = observable({ x: 1 })
The behavior can be modified with
observable.ref
annotation ordeep: false
option.Not sure if that's what you're asking about.