-
-
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
Introduce support for Symbol named observable properties #1809
Comments
Addition, if using mobx@4, it just fails silently rather than throwing the error out in version 5. |
I fail to understand the use-case of this scenario, you want to create a dynamic key? |
Hi @ItamarShDev, The question is mobx doesn't work when using a Symbol as an object key.
I am maintaining a vue.js project, and bring mobx to do state management rather than the native vue way. The original practice of this project using sth like |
Thanks for the explanation @kimochg ! |
If Symbols where supported, could it conflict with current or future well-known symbols like: Symbol.iterator, Symbol.toStringTag, etc. ? Should there be a list of excluded symbols ? Disclaimer: I am currently taking advantage of the fact that symbols are ignored by MobX in my MobX extension library: https://github.com/jlgrall/mobx-patch-computedTree, but I can find another way. |
Mobx ignores non-enumerable props (like symbols) in
I don't think so. Symbols are accessible via |
@mweststrate What do you think about this issue? |
👍 from me also. We I'm trying to use symbols as keys for mixin attached private properties to a class and also make them observable, but mobx throws (up) 😄 |
I think symbol named properties should probably behave the same as string named properties. That is, if they are enumerable, they should be picked up. Marking it as feature. Contributions are welcome. Even a solid test suite would already give a great head start! Note that this has quite some impact on typings as well, as in things like I guess |
@mweststrate Looking forward to this feature. I am trying the same thing with @dr0p , but mobx doesn't work. Just as the following code snippet:
But mobx throws this error:
|
I'd like to make my own iterable an observable object, but this issue is preventing me from doing so : ). In this case though, the Symbol shouldn't be enumerable, preferably. Basic use case for us is an iterable datastructure whose data source can differ (e.g. array or a generator function). |
@jheeffer If I follow correctly, you don't need the symbol prop observable. So if you can live with some kind of factory function, you can introduce the iterator to observable object: const bar = mobx.observable(foo)
Object.defineProperty(bar, Symbol.iterator, {
enumerable: false,
get() {
return this.x[Symbol.iterator].bind(this.x);
}
}) |
@urugator you're right, that could work too. Out of the box keeping an object iterable would be nice but I understand the trade-offs : ) |
👋 Hey folks, I've tried to kicked this off in PR #1944, please feel free to have a look n' review if you have the time. |
Released as 4.10.0 / 5.10.0. Thanks @loklaan ! |
YES 🎉 |
Welcome to MobX. Please provide as much relevant information as possible!
I have a:
Please tick the appropriate boxes. Feel free to remove the other sections.
Please be sure to close your issues promptly.
What
error
'set' on proxy: trap returned falsish for property 'Symbol(count)'
threw when using Symbol as key in an observable,How to reproduce
The text was updated successfully, but these errors were encountered: