-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Object.defineProperty and useProxies: "ifavailable" #2876
Comments
Dangerous way of doing that:
It should be completely fine to use for storing hidden non-observable meta data and it should perform a lot better in such case. If someone could pinpoint me to the MST sources from where the One way or another, I will add the "safe" function to the api. |
@urugator I'm wondering, should the current interception not just forward the defineProperty to the target using Reflect, rather than going through MobX administration? I don't think we officially support using
|
Support is mentioned in 6.1.0 changelog
It's easier to support, than treat it as a special case. We still need to be able to define property internally. All the APIs that introduce new prop, eventually delegate to single method Another more or less related thing is that these proxy traps not always map 1-to-1 to single method, they can be called by engine on different occasions. Eg. currently we don't support subscription for |
|
@urugator Also, It looks like that's all. |
@BATCOH Since these worked prior 6.1 and |
Proxies used to be faster, is this no longer the case?
I think the work around in general is fine, MST has more specific integrations involving the Possible mitigation:
|
I've not tested, but I can't imagine how they could be faster (with object). There is exactly the same machinery (you still have a
Exposing and using the official |
Once released, MST should call |
Intended outcome:
A way to define a property on an observable object with
useProxies: "ifavailable"
and without error.Actual outcome:
Mobx with
useProxies: "ifavailable"
gives an error in dev mode when trying to set an observable object property viaObject.defineProperty
.Obviously in this case the error is relevant, the problem is with its description.
Use 'defineProperty' from 'mobx' instead.
But there is no
defineProperty
export in mobx. I think at least the description should be corrected or such method should be provided.And I haven't found an easy way to suppress this error if I'm sure of what I'm doing other than disabling
useProxies: 'ifavailable'
.Specifically,
mobx-state-tree
usesObject.defineProperty
to store some internal data. And working withmobx-state-tree
in "ifavailable" mode is currently impossible.https://codesandbox.io/s/mobx-state-tree-todolist-ifavailable-t9w2z?file=/index.js
Maybe I should post an issue to MST too, but it doesn't seem to make much sense without offering a solution to replace
Object.defineProperty
with something else.How to reproduce the issue:
https://codesandbox.io/s/mobx-defineproperty-16wyc?file=/src/index.js
Versions
"mobx": "^6.1.8"
The text was updated successfully, but these errors were encountered: