-
-
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
Utilizing Proxy api when possible-feasable? #336
Comments
I think it is doable, on the other hand I am a bit weary to do to this as long as it cannot be standardized upon, currently MobX is already taking care of differences between TypeScript and Babel transpiled code, and I think using proxies where available introduces a separate variable in the equation. I think it is nice to do in some major version, so that for example more fundamental problems can be fixed with it, like observable arrays not being real arrays :) That being said, always feel free to take a shot at it, if the changes appear to be small, it might interesting to adopt it early. |
Just a heads up: The GoogleChrome team has build a polyfill for Proxies: https://github.com/GoogleChrome/proxy-polyfill. At the time of this writing it does only support |
You make it sound like it will support "defineProperty" trap in the future. It won't, that is impossible unfortunately. |
@capaj That makes sense. Thanks for clearing that up 👍 |
My current idea is to introduce I think that is a nice case to start working with Proxies, learn about their caveats, performance etc. It has a clear use case and advantage over the current getter / setter implementation, yet there is a fallback for those needing to support browsers without proxies (probably the most of us): Example: const todos = dynamicObject({
"a23bf": { completed: false}
})
autorun(() => console.log(Object.keys(todos)))
// prints "a23bf"
todos["a8235"] = { completed: true}
// prints "a23bf", "a8235", something that currently can only be achieved through observable maps |
Just in case you haven't seen these... |
As we've discussed numerous times in regards to Proxies- it would make sense to use those instead of getters/setters.
My question is on you @mweststrate - is it feasible from your perspective to plugin proxies into current MobX codebase? So that when a browser supports it, MobX would set it's traps using Proxies instead of getters/setters? I haven't looked into the codebase very deeply, but to me, it seems like it could be done if we created Proxy versions for observablearray.ts and observableobject.ts compatible with the current API.
What do you think @mweststrate ? Worth a try?
The text was updated successfully, but these errors were encountered: