-
-
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
Fix #2871 toJS throws with configure({ useProxies: "ifavailable" }) #2873
Conversation
🦋 Changeset detectedLatest commit: 97523ba The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See comment, I think the proposed fix is incorrect; even in ES5 mode, toJS should still be reacting to key addition / removals, and I don't think that is the case with the current solution? (We might be missing an explicit test for that)
const res = cache(__alreadySeen, source, {}) | ||
getPlainObjectKeys(source).forEach((key: any) => { | ||
res[key] = toJSHelper(source[key], __alreadySeen) | ||
;((source as any) as IIsObservableObject)[$mobx].ownKeys_().forEach((key: any) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the fix here is incorrect; we should use keys(source)
as basis for the loop, and not use getPlainObjectKeys
, to make sure that toJS
will track key additions, even when it is used in ES5 mode. There are probably subtle differences between keys
and getPlainObjectKeys
that might need to be addressed, but we should use keys
as basis, or keep it as implemented here, but make sure a read to the keys atom is registered.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
adm.ownKeys_
handles the subscription to keys atom the same way as keys(object)
. We simply don't have ownKeys_
exposed via object-api
so I call it directly on administration.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just to clarify further, there is no longer any interesting logic (like keyAtom subscriptions) in object-api or in proxy handler. They simply delegate to adm
and everything is done there.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok great, that should work!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Leaving the merging up to you, in case you want to merge the open PR's in a specific order :)
Fixes: #2871 in BC manner.
We may want to reconsider which kind fo keys
toJS
returns.