-
-
Notifications
You must be signed in to change notification settings - Fork 122
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
createViewModel doesn't respect { deep: false } #170
Comments
Even worse: after doing |
@mweststrate I there any way to know that provided mobx observable has been created shallow? |
isn't the note from the docs says it would? @sheerun
|
It would be true for deep observed objects, but shoudn't be the case for { deep: false } observables |
Looking at the code, it seems that this should be an observable by design. |
It should be an observable, but in my case it should be shallow observable, not deep one. |
I think this is a bug indeed, and that the modifiers should be preserved. @sheerun would you mind creating a PR with some unit tests demonstrating the erroneous behavior and verifying a potential fix? |
I can but first I need an answer to my previous question because I couldn't find how, and without this it's not possible to implement any fix:
|
Hacky inefficient solution: function isShallow(thing) {
if (isObservableObject(thing)) {
return !isObservable(thing.$mobx.defaultEnhancer([]));
}
if (isObservableArray(thing)) {
return !isObservable(thing.$mobx.enhancer([]));
}
if (isObservableMap(thing)) {
return !isObservable(thing.enhancer([]));
}
return false; //?
}
[
// deep
observable({}),
observable([]),
observable(new Map()),
// shallow
observable({}, {}, { deep: false }),
observable([], { deep: false }),
observable(new Map(), { deep: false })
].forEach(thing => console.log(isShallow(thing))); |
I think this PR requires some additional reflection methods in MobX first, a proposal is welcome (on that repo) |
Closing for inactivity |
It happens with mobx-utils 5.1.0:
It happens that I pass model to library that tries to do isArray check on some internal array of unit which mobx converted to ObservableArray. I think createViewModel could preserve shallowness to prevent such errors.
The text was updated successfully, but these errors were encountered: