Skip to content

Commit 165e848

Browse files
committed
connect: Demonstrate SelectorProps pattern.
This is the one kind of annotation we do need at some call sites of `connect`. Specifically: * when `mapStateToProps` actually takes a `props` parameter, * we need to annotate its *return* type, as here. Before merging the Flow upgrade, we'll need to do the same thing on the other call sites. Fortunately that shouldn't be much work.
1 parent 81932ca commit 165e848

File tree

3 files changed

+27
-14
lines changed

3 files changed

+27
-14
lines changed

src/chat/UnreadNotice.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,16 @@ const styles = StyleSheet.create({
3030
},
3131
});
3232

33+
type SelectorProps = {|
34+
unreadCount: number,
35+
|};
36+
3337
type Props = {|
34-
dispatch: Dispatch,
3538
limited: boolean,
3639
narrow: Narrow,
37-
unreadCount: number,
40+
41+
dispatch: Dispatch,
42+
...SelectorProps,
3843
|};
3944

4045
class UnreadNotice extends PureComponent<Props> {
@@ -65,6 +70,6 @@ class UnreadNotice extends PureComponent<Props> {
6570
}
6671
}
6772

68-
export default connect((state, props) => ({
73+
export default connect((state, props): SelectorProps => ({
6974
unreadCount: getUnreadCountForNarrow(state, props.narrow),
7075
}))(UnreadNotice);

src/compose/ComposeBox.js

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import type {
1212
UserOrBot,
1313
Dispatch,
1414
Dimensions,
15-
GlobalState,
1615
} from '../types';
1716
import { connect } from '../react-redux';
1817
import {
@@ -47,18 +46,22 @@ import { getDraftForNarrow } from '../drafts/draftsSelectors';
4746
import TopicAutocomplete from '../autocomplete/TopicAutocomplete';
4847
import AutocompleteView from '../autocomplete/AutocompleteView';
4948

50-
type Props = {|
49+
type SelectorProps = {|
5150
auth: Auth,
52-
narrow: Narrow,
5351
usersByEmail: Map<string, UserOrBot>,
54-
draft: string,
55-
lastMessageTopic: string,
52+
safeAreaInsets: Dimensions,
5653
isAdmin: boolean,
5754
isAnnouncementOnly: boolean,
5855
isSubscribed: boolean,
5956
editMessage: ?EditMessage,
60-
safeAreaInsets: Dimensions,
57+
draft: string,
58+
lastMessageTopic: string,
59+
|};
60+
61+
type Props = {|
62+
narrow: Narrow,
6163
dispatch: Dispatch,
64+
...SelectorProps,
6265
|};
6366

6467
type State = {|
@@ -402,7 +405,7 @@ class ComposeBox extends PureComponent<Props, State> {
402405
}
403406
}
404407

405-
export default connect((state: GlobalState, props) => ({
408+
export default connect((state, props): SelectorProps => ({
406409
auth: getAuth(state),
407410
usersByEmail: getActiveUsersByEmail(state),
408411
safeAreaInsets: getSession(state).safeAreaInsets,

src/nav/ChatNavBar.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import React, { PureComponent } from 'react';
44
import { View } from 'react-native';
55

6-
import type { Dispatch, GlobalState, Narrow } from '../types';
6+
import type { Dispatch, Narrow } from '../types';
77
import { connect } from '../react-redux';
88
import styles, { BRAND_COLOR } from '../styles';
99
import Title from '../title/Title';
@@ -13,10 +13,15 @@ import { foregroundColorFromBackground } from '../utils/color';
1313
import { navigateBack } from '../actions';
1414
import { ExtraButton, InfoButton } from '../title-buttons/titleButtonFromNarrow';
1515

16-
type Props = {|
17-
dispatch: Dispatch,
16+
type SelectorProps = {|
1817
backgroundColor: string,
18+
|};
19+
20+
type Props = {|
1921
narrow: Narrow,
22+
23+
dispatch: Dispatch,
24+
...SelectorProps,
2025
|};
2126

2227
class ChatNavBar extends PureComponent<Props> {
@@ -44,6 +49,6 @@ class ChatNavBar extends PureComponent<Props> {
4449
}
4550
}
4651

47-
export default connect((state: GlobalState, props) => ({
52+
export default connect((state, props): SelectorProps => ({
4853
backgroundColor: getTitleBackgroundColor(props.narrow)(state),
4954
}))(ChatNavBar);

0 commit comments

Comments
 (0)