-
-
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
[Flow]: Add JS objects to Map.mergeIn & Map.mergeDeepIn #987
[Flow]: Add JS objects to Map.mergeIn & Map.mergeDeepIn #987
Conversation
Thank you for your pull request. As you may know, we require contributors to sign our Contributor License Agreement, and we don't seem to have you on file and listed as active anymore. In order for us to review and merge your code, please email cla@fb.com with your details so we can update your status. |
Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Facebook open source project. Thanks! |
Dead? Pshhh. It's not like we let this pull request sit for 15 months without responding. Anyway my guess is that this has been abandoned. I was gonna ask for some sort of test if this was still alive, but I'm just gonna drop it. Sorry for letting this be quiet for so long :P and if you want to keep working on this please feel free to reopen! |
hey, thanks for bringing it back. I didn't mean to insult you. I just didn't see too much activity on any pull request at that time. Anyway, if you want a flow definition here (vs having one in |
What's the "standard thing to do" around having a flow definition here vs in flow-typed? We should have a correct flow-typing as opposed to an incorrect one but I don't particularly have a stance on where it should go. Probably here? So I think it is awesome if you could help maintain this - so here's a question - do you think it makes sense when people submit a change to the flowtypes, to ask for a test that exercises the new type? I just want to make sure that we are protecting against stuff breaking as we improve things. |
In my opinion it's better when definitions are in the repo. For obvious reasons - it becomes immediately available to everyone who uses it. I'll ask in this PR for their point of view on it. We might put it here for now and we will see how it evolves. When it comes to testing, yes, I do think that tests are necessary. And tests are implemented here. I just need to make |
Sorry that I spammed across few PRs to move people's work to my PR in |
Yeah I understand, it's cool that you were spamming your alternative, I feel your pain man. But now that I am paying attention I would like the immutable.js repo to be all nice and things. I could really use your help reviewing Flow stuff though since I'm sort of a Flow noob myself. So what do you think we should do for this pull request - just accept it, or ask for some extra test type stuff, or what? |
I think that the order should be the following:
|
I made the tests run on travis in #878 |
@lacker @wokalski Hey guys, sorry for being quiet, I stopped visiting this PR after some time and missed the activity here as my gh became too noisy these days. According to this comment serving shadow files w/ typings is still the way to go, so I guess this PR still makes sense. AFAIU this PR is currently blocked by #878, let me know if I misread something and let me know what & when needs to be done here to get this merged. Thanks! |
OK so #878 is in now so we have some Flow type refactorings and also you can now test flow types. Would you mind updating to merge those changes in, and also adding a test that catches these changes? Thanks! |
@lacker Ok! I'll look into this on weekend 👍 |
71d7640
to
bfe796e
Compare
bfe796e
to
2d26e0c
Compare
One note: it's not related to this PR, but when I run |
I'm a bit confused. The diff shows that my changes are reapplied. Could you rebase the PR against current master? Possibly your fork's master is probably behind |
@wokalski I think I rebased everything against master (flow tests weren't in my initial fork), let me check it one more time. |
If you look at this file and the contents of the PR, you can see that something is off. Maybe conflict resolution gone wrong? |
mergeIn( | ||
keyPath: ESIterable<any>, | ||
...iterables: (ESIterable<any> | { [key: string]: any })[] | ||
): Map<K,V>; |
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.
This makes me a bit confused. The mergeIn
does change the type of the map, doesn't it? If so we (sadly) might need to turn V
into 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 used any
b/c of this: http://facebook.github.io/immutable-js/docs/#/Map/merge
If any of the values provided to merge are not Iterable (would return false for Immutable.Iterable.isIterable) then they are deeply converted via Immutable.fromJS before being merged. However, if the value is an Iterable but includes non-iterable JS objects or arrays, those nested values will be preserved.
So if V
is also Map
or List
, I can pass Object
or Array
as V
and it still should be valid as it will be converted to Map
or List
by fromJS
.
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.
This part is correct. However in flow Map
and List
are parametrised (generic). So if you merge ESIterable<any>
with Map<string, string>
it becomes Map<string, any>
, Map<string, Map<string | number>> would become
Map<string, any>`.
AFAIK there's no way to overload the declaration for different V
types so that we would have one for V: Map
and one for V: List
case.
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, so your suggestion is to turn those to this, right?
mergeIn(
keyPath: ESIterable<any>,
...iterables: (ESIterable<any> | { [key: string]: any })[]
): Map<K,any>;
mergeDeepIn(
keyPath: ESIterable<any>,
...iterables: (ESIterable<any> | { [key: string]: any })[]
): Map<K,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.
Yes, iff my reasoning is correct.
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.
Also I had two further thoughts:
- maybe the key path could be
ESIterable<K>
to make it type safe? - It should also be possible to merge it with a
Map
, not only an object, right?
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.
Done.
maybe the key path could be ESIterable to make it type safe?
Agreed, done.
It should also be possible to merge it with a Map, not only an object, right?
Right, also w/ List
etc., but I think it's handled by ESIterable<K>
. Tests added.
@@ -228,6 +228,9 @@ stringToNumber = Map({'a': 1}).removeIn([], 0) | |||
stringToNumber = Map({'a': 1}).mergeIn([], []) | |||
stringToNumber = Map({'a': 1}).mergeDeepIn([], []) | |||
|
|||
anyMap = Map({'a': {}}).mergeIn(['a'], { b: 2 }) | |||
anyMap = Map({'a': {}}).mergeDeepIn(['a'], { b: 2 }) |
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.
Needs some tests for false positives. Put // $ExpectError
on a line preceding a code which should output an error for these.
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.
Done.
@wokalski That's weird, there was conflict only in |
It would be awesome. |
@wokalski Just pasted contents and I see only my changes in diff: https://cl.ly/iPzf |
omg, sorry. This is what you call a 5 am review. I didn't notice that referred to |
@wokalski Np, I replied to comments 👍 |
This is awesome. Great work 👍 Now it's up to somebody with commit access to merge it. |
Thanks @alexfedoseev for submitting this and thanks @wokalski for reviewing! |
Adds vanilla JS objects to flow typings of
Immutable.Map
'smergeIn
&mergeDeepIn
.