Prep commits for new avatar_url handling (#4157)#4171
Prep commits for new avatar_url handling (#4157)#4171chrisbobbe merged 3 commits intozulip:masterfrom
avatar_url handling (#4157)#4171Conversation
| declare type mockStore = { <S, A>(state: S): mockStoreWithoutMiddleware<S, A>, ... }; | ||
| declare type DispatchAPI<A> = (action: A) => A; | ||
| declare type Dispatch<A: $ReadOnly<{ type: string, ... }>> = DispatchAPI<A>; | ||
| declare interface Dispatch<S, A> { |
There was a problem hiding this comment.
Mm, the S type argument is unnecessary (making a comment so I remember to address this in my next revision, along with code-review feedback).
There was a problem hiding this comment.
(and a code comment here saying that we've edited this bit would be good too)
a2be911 to
6848116
Compare
|
Just resolved some conflicts; awaiting review. 🙂 |
6848116 to
d514eb8
Compare
In an upcoming commit, we'll change the Dispatch type in this libdef to play nicely with our async redux-thunk actions. I don't see an easy way to give the libdef the flexibility to give different types depending on what middleware is used, so, we hard-code it for ourselves, since we know we'll be using redux-thunk for the foreseeable future. This means we probably can't reasonably make a PR to FlowTyped, even though this is (surprisingly) one of the few libraries we use that does have a libdef hosted by FlowTyped. Ah, well. Here, we just move the file, delete the metadata at the top, and run our auto-formatting. [cherry-picked from zulip#4171]
This version [1] is marked for a higher version of Flow than we're using now (v0.104 and above), but there aren't any errors on our Flow version (v0.98). So, take it. This gets us a particular change to the Dispatch type [2] that goes in the right direction...until we clobber it with our own Dispatch that accounts for async redux-thunk actions, I suppose. Ah well, there are a few minor changes that we might like to have, and this is a later version, so, might as well. [1]: https://github.com/flow-typed/flow-typed/blob/c4f47bdda/definitions/npm/redux-mock-store_v1.2.x/flow_v0.104.x-/redux-mock-store_v1.2.x.js [2]: flow-typed/flow-typed#3803 [cherry-picked from zulip#4171]
As foreshadowed in the preceding commits, we can't really expect a FlowTyped-hosted libdef to have the flexibility to give us the right types for Dispatch on the condition that we pass `thunk` as a piece of middleware. We're decidedly using `thunk`, so, hard-code support for it here by allowing dispatch to be called with a redux-thunk async action. We're pretty consistent with having correct types for such an action, so not much is lost by typing its arguments loosely as `Function, Function`, and from some attempts, it seems much easier than nailing down something exactly right. [cherry-picked from zulip#4171]
It looks like this was added with the idea that we'd use it in more places than we actually have. It adds a slight bit of convenience; with this mock, we can avoid having to write `configureStore([thunk])` a bunch of times. But that's a very small amount of boilerplate. The mock doesn't seem to have any other purpose that might be part of a unit-testing strategy. Removing it makes it possible to use the libdef without contorting it more drastically than we already have. [cherry-picked from zulip#4171]
The added fields were gleaned from a real-life example observed with `redux-logger`. [cherry-picked from zulip#4171]
d514eb8 to
a812273
Compare
|
Just rebased again, following the RN v0.61 upgrade (no conflicts), awaiting review. 🙂 |
a812273 to
7a94382
Compare
|
Ah, oops: Just found a few things to do better, so I pushed again; hopefully this didn't interrupt a review. I'll move on to something else now so you don't have to worry about possible interruptions again, and I'll post here if for some reason I need to make more changes. |
|
Mm, looks like there are some conflicts—fixing those now. edit: Fixed. |
7a94382 to
ea33d84
Compare
In an upcoming commit, we'll change the Dispatch type in this libdef to play nicely with our async redux-thunk actions. I don't see an easy way to give the libdef the flexibility to give different types depending on what middleware is used, so, we hard-code it for ourselves, since we know we'll be using redux-thunk for the foreseeable future. This means we probably can't reasonably make a PR to FlowTyped, even though this is (surprisingly) one of the few libraries we use that does have a libdef hosted by FlowTyped. Ah, well. Here, we just move the file, delete the metadata at the top, and run our auto-formatting. [cherry-picked from zulip#4171]
This version [1] is marked for a higher version of Flow than we're using now (v0.104 and above), but there aren't any errors on our Flow version (v0.98). So, take it. This gets us a particular change to the Dispatch type [2] that goes in the right direction...until we clobber it with our own Dispatch that accounts for async redux-thunk actions, I suppose. Ah well, there are a few minor changes that we might like to have, and this is a later version, so, might as well. [1]: https://github.com/flow-typed/flow-typed/blob/c4f47bdda/definitions/npm/redux-mock-store_v1.2.x/flow_v0.104.x-/redux-mock-store_v1.2.x.js [2]: flow-typed/flow-typed#3803 [cherry-picked from zulip#4171]
As foreshadowed in the preceding commits, we can't really expect a FlowTyped-hosted libdef to have the flexibility to give us the right types for Dispatch on the condition that we pass `thunk` as a piece of middleware. We're decidedly using `thunk`, so, hard-code support for it here by allowing dispatch to be called with a redux-thunk async action. We're pretty consistent with having correct types for such an action, so not much is lost by typing its arguments loosely as `Function, Function`, and from some attempts, it seems much easier than nailing down something exactly right. [cherry-picked from zulip#4171]
It looks like this was added with the idea that we'd use it in more places than we actually have. It adds a slight bit of convenience; with this mock, we can avoid having to write `configureStore([thunk])` a bunch of times. But that's a very small amount of boilerplate. The mock doesn't seem to have any other purpose that might be part of a unit-testing strategy. Removing it makes it possible to use the libdef without contorting it more drastically than we already have. [cherry-picked from zulip#4171]
The added fields were gleaned from a real-life example observed with `redux-logger`. [cherry-picked from zulip#4171]
In an upcoming commit, we'll change the Dispatch type in this libdef to play nicely with our async redux-thunk actions. I don't see an easy way to give the libdef the flexibility to give different types depending on what middleware is used, so, we hard-code it for ourselves, since we know we'll be using redux-thunk for the foreseeable future. This means we probably can't reasonably make a PR to FlowTyped, even though this is (surprisingly) one of the few libraries we use that does have a libdef hosted by FlowTyped. Ah, well. Here, we just move the file, delete the metadata at the top, and run our auto-formatting. [cherry-picked from zulip#4171]
This version [1] is marked for a higher version of Flow than we're using now (v0.104 and above), but there aren't any errors on our Flow version (v0.98). So, take it. This gets us a particular change to the Dispatch type [2] that goes in the right direction...until we clobber it with our own Dispatch that accounts for async redux-thunk actions, I suppose. Ah well, there are a few minor changes that we might like to have, and this is a later version, so, might as well. [1]: https://github.com/flow-typed/flow-typed/blob/c4f47bdda/definitions/npm/redux-mock-store_v1.2.x/flow_v0.104.x-/redux-mock-store_v1.2.x.js [2]: flow-typed/flow-typed#3803 [cherry-picked from zulip#4171]
As foreshadowed in the preceding commits, we can't really expect a FlowTyped-hosted libdef to have the flexibility to give us the right types for Dispatch on the condition that we pass `thunk` as a piece of middleware. We're decidedly using `thunk`, so, hard-code support for it here by allowing dispatch to be called with a redux-thunk async action. We're pretty consistent with having correct types for such an action, so not much is lost by typing its arguments loosely as `Function, Function`, and from some attempts, it seems much easier than nailing down something exactly right. [cherry-picked from zulip#4171]
It looks like this was added with the idea that we'd use it in more places than we actually have. It adds a slight bit of convenience; with this mock, we can avoid having to write `configureStore([thunk])` a bunch of times. But that's a very small amount of boilerplate. The mock doesn't seem to have any other purpose that might be part of a unit-testing strategy. Removing it makes it possible to use the libdef without contorting it more drastically than we already have. [cherry-picked from zulip#4171]
The added fields were gleaned from a real-life example observed with `redux-logger`. [cherry-picked from zulip#4171]
In an upcoming commit, we'll change the Dispatch type in this libdef to play nicely with our async redux-thunk actions. I don't see an easy way to give the libdef the flexibility to give different types depending on what middleware is used, so, we hard-code it for ourselves, since we know we'll be using redux-thunk for the foreseeable future. This means we probably can't reasonably make a PR to FlowTyped, even though this is (surprisingly) one of the few libraries we use that does have a libdef hosted by FlowTyped. Ah, well. Here, we just move the file, delete the metadata at the top, and run our auto-formatting. [cherry-picked from zulip#4171]
This version [1] is marked for a higher version of Flow than we're using now (v0.104 and above), but there aren't any errors on our Flow version (v0.98). So, take it. This gets us a particular change to the Dispatch type [2] that goes in the right direction...until we clobber it with our own Dispatch that accounts for async redux-thunk actions, I suppose. Ah well, there are a few minor changes that we might like to have, and this is a later version, so, might as well. [1]: https://github.com/flow-typed/flow-typed/blob/c4f47bdda/definitions/npm/redux-mock-store_v1.2.x/flow_v0.104.x-/redux-mock-store_v1.2.x.js [2]: flow-typed/flow-typed#3803 [cherry-picked from zulip#4171]
As foreshadowed in the preceding commits, we can't really expect a FlowTyped-hosted libdef to have the flexibility to give us the right types for Dispatch on the condition that we pass `thunk` as a piece of middleware. We're decidedly using `thunk`, so, hard-code support for it here by allowing dispatch to be called with a redux-thunk async action. We're pretty consistent with having correct types for such an action, so not much is lost by typing its arguments loosely as `Function, Function`, and from some attempts, it seems much easier than nailing down something exactly right. [cherry-picked from zulip#4171]
It looks like this was added with the idea that we'd use it in more places than we actually have. It adds a slight bit of convenience; with this mock, we can avoid having to write `configureStore([thunk])` a bunch of times. But that's a very small amount of boilerplate. The mock doesn't seem to have any other purpose that might be part of a unit-testing strategy. Removing it makes it possible to use the libdef without contorting it more drastically than we already have. [cherry-picked from zulip#4171]
The added fields were gleaned from a real-life example observed with `redux-logger`. [cherry-picked from zulip#4171]
|
And now more conflicts, from commits in #4187. I'll fix these now. (edit: Fixed!) |
ea33d84 to
5eaf773
Compare
gnprice
left a comment
There was a problem hiding this comment.
A few comments below, and otherwise looks good! Thanks for improving all these test files.
| }; | ||
|
|
||
| const serverMessage: ServerMessage = { | ||
| ...(omit(eg.streamMessage(), 'reactions'): $Diff<Message, { reactions: mixed }>), |
There was a problem hiding this comment.
Is the omit needed here? The property mentioned after the spread should clobber it anyway.
There was a problem hiding this comment.
Definitely sounds reasonable.
It seems like Flow happily verifies that there will be a correct type at reactions after the spread, but only with the omit (or something like it) in place. Even though it's in the spec (er, I'm pretty sure) that later-mentioned properties will clobber earlier-mentioned ones, it seems like Flow maybe doesn't know that, or in any case doesn't like there being two different, competing (and both present) values for a single property.
If I take away the omit:
Error ┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈ src/api/messages/__tests__/migrateMessages-test.js:23:40
Cannot assign object literal to serverMessage because:
• property user is missing in object type [1] but exists in object type [2] in array element of property reactions.
• property user_id is missing in object type [2] but exists in object type [1] in array element of property
reactions.
src/api/messages/__tests__/migrateMessages-test.js
20│ },
21│ };
22│
23│ const serverMessage: ServerMessage = {
24│ ...eg.streamMessage(),
25│ reactions: [serverReaction],
26│ };
27│
28│ const input: ServerMessage[] = [serverMessage];
29│
src/api/messages/getMessages.js
[2] 33│ reactions: $ReadOnlyArray<ServerReaction>,
src/api/modelTypes.js
[1] 493│ reactions: $ReadOnlyArray<Reaction>,
There was a problem hiding this comment.
Hmm, indeed.
It looks like this is one of the issues discussed here:
https://medium.com/flow-type/spreads-common-errors-fixes-9701012e9d58
Spreads now overwrite properties instead of inferring unions
and it's fixed in Flow v0.111.
Which, checking our next RN upgrade issue #3782... we'll get with that upgrade to RN v0.62! Should be a lot of Flow improvement in that upgrade -- that'll be a happy day.
There was a problem hiding this comment.
So this is a fine workaround; but let's add a comment mentioning Flow v0.111. (So that when we do that upgrade we can easily find this in a grep and make it one of the spots where we improve the types as a followup.)
| }, | ||
| ]), | ||
| ).not.toContain('&<'); | ||
| const user = eg.makeUser({ name: '&<av' }); |
There was a problem hiding this comment.
Does this still have the &< sequence in the avatar_url? One of the things this is testing is that that gets properly encoded.
There was a problem hiding this comment.
It currently does, meaning eg.makeUser has this for avatar_url:
`https://zulip.example.org/yo/avatar-${name}.png`,
But that's up to exampleData to freely stop doing if it wants to. Might as well pin to a particular avatar_url and email here by clobbering those properties; I'll do that.
5eaf773 to
86a7e0f
Compare
|
Thanks for the review! Just pushed those changes. You may want to see my note at #4171 (comment) about the |
|
Actually, since you said at #4171 (review) that it otherwise looks good, I'll go ahead and merge the changes to the |
86a7e0f to
e835828
Compare
OK, I ended up merging all the commits except for two you commented on that I don't have an immediate need for, so you can see my responses to them when you get a chance (#4171 (comment) and #4171 (comment)). The two that weren't merged weren't at the tip in the revision you reviewed, but I checked that they could stand apart from the rest of the branch, and I ran |
e835828 to
70502de
Compare
|
I said:
OK, just added this. It was a little tricky getting |
|
The new commit lgtm! Re |
70502de to
9c52958
Compare
|
OK, done, thanks for the review! |
In a revision of my work for #4157, I noticed that there were some necessary changes to some test files, and some of these files haven't been type-checked or taken advantage of the work we've put into
src/__tests__/lib/exampleData.js.Rather than continue editing these files in this unstable state, pave the way for better edits by type-checking them and using that example data. 🙂 And fix a few bugs I've noticed.
The revision that informed these changes was one where the type for
avatar_urlon theMessagetype (not just that field on theUsertype) was changed. I think this might be a direction we'll go in (e.g., the type might be a union of all subclasses ofAvatarURLexceptIdleAvatarURL); I'm thinking of the discussion around here. In any case, that explains whyfetchActions-test.jswas touched (fetchMessagesis in there).There will be some more of this; I know at least
src/webview/__tests__/webViewHandleUpdates-test.jshas some stuff that I'm still figuring out.