-
-
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
Implemented toJS
in such a way that it only recurses into observables
#589
Conversation
@mweststrate From what you described this sounds like it solves the problem I was seeing.
I would agree with this. In fact, that was how I thought |
@mweststrate Nice! By the way, what do you think about having non-enumerable |
yeah thought about that, but it is a bit nasty as such a method could Op ma 3 okt. 2016 17:20 schreef Andy Kogut [email protected]:
|
@mweststrate, I agree, but that could be useful for debugging. May be call it |
hmm for debugging we could simply introduce object.$mobx.toJS() :) Op ma 3 okt. 2016 17:31 schreef Andy Kogut [email protected]:
|
@mweststrate, yeah, that should work :-) |
@andykog mind opening a separate issue? or creating a PR ;-) ? Op ma 3 okt. 2016 om 17:40 schreef Andy Kogut [email protected]:
|
I'll do a PR |
This broke our app (and it wasn't the first time with an update). It would be nice if this could be solved differently in the future:
Please have no hauptversionsnummernerhöhungsangst :) |
@donaldpipowitch you're right, I'm definitely scared of major number version bumps :'(. I'll gonna deal with that and join the anonymous-club-for-only-minor-version-bumpers |
No problem. Making frameworks is hard and you do a good job. |
@donaldpipowitch that's why we're only making a library 😀 |
As an example for the 2nd point:
It may not be such a rare case. I ended up with an array of arrays and a computed getter like this: @observable _rows = [ ] ; This is because some components of other libraries do rely on a is-array-test that requires the array to be truly an array (and it is out of my hand to change anything). For instance, this happens with propTypes in react. now, toJS( my_class.rows ) fails to convert because the elements of rows are an observable but the first element of toJS is a (non-observable) array. As you have flags as second argument, I think it will be a good idea to put a flag that simply transverse the object without looking if it is observable or not. Or maybe a flag to consider the arrays as you have one for the objects. |
This PR fixes #566 / #568. Previously
toJS
made a deep clone of any javascript structure. This PR changes the behavior; it only clones observables, but leaves all other objects as is. I think that is what most people would expect from this function (I would)For backward compatibility, people relying on the old behavior can use
toJSlegacy
(deprecated). The old behavior can probably be simulated by using e.g.lodash
:const clone = deepClone(toJs(observable))
. (MaybetoJS
is not even needed there)Some questions:
toJS
and hence not converted. Is that a problem? (I think it is a rare case)So for example
what do you think @andykog @maxdeviant?
EDIT: fixed example above