diff --git a/src/account-info/AccountDetailsScreen.js b/src/account-info/AccountDetailsScreen.js index 1ee7144b747..e04796500a2 100644 --- a/src/account-info/AccountDetailsScreen.js +++ b/src/account-info/AccountDetailsScreen.js @@ -1,9 +1,8 @@ /* @flow */ import React, { Component } from 'react'; -import { connect } from 'react-redux'; import type { Auth, Actions, Orientation, UserType } from '../types'; -import boundActions from '../boundActions'; +import connectWithActions from '../connectWithActions'; import { getAuth, getAccountDetailsUser } from '../selectors'; import { Screen } from '../common'; import AccountDetails from './AccountDetails'; @@ -47,11 +46,8 @@ class AccountDetailsScreen extends Component { } } -export default connect( - state => ({ - auth: getAuth(state), - user: getAccountDetailsUser(state), - orientation: state.app.orientation, - }), - boundActions, -)(AccountDetailsScreen); +export default connectWithActions(state => ({ + auth: getAuth(state), + user: getAccountDetailsUser(state), + orientation: state.app.orientation, +}))(AccountDetailsScreen); diff --git a/src/account-info/LogoutButton.js b/src/account-info/LogoutButton.js index 7bb4b30be7a..dc7886b6b12 100644 --- a/src/account-info/LogoutButton.js +++ b/src/account-info/LogoutButton.js @@ -1,10 +1,9 @@ /* @flow */ import React, { PureComponent } from 'react'; import { StyleSheet } from 'react-native'; -import { connect } from 'react-redux'; import type { Actions, Auth } from '../types'; -import boundActions from '../boundActions'; +import connectWithActions from '../connectWithActions'; import { ZulipButton } from '../common'; import unregisterPush from '../api/unregisterPush'; import { getAuth } from '../selectors'; @@ -52,11 +51,8 @@ class LogoutButton extends PureComponent { } } -export default connect( - state => ({ - auth: getAuth(state), - accounts: state.accounts, - pushToken: state.realm.pushToken, - }), - boundActions, -)(LogoutButton); +export default connectWithActions(state => ({ + auth: getAuth(state), + accounts: state.accounts, + pushToken: state.realm.pushToken, +}))(LogoutButton); diff --git a/src/account-info/SwitchAccountButton.js b/src/account-info/SwitchAccountButton.js index 6df5113043a..a56eff925ae 100644 --- a/src/account-info/SwitchAccountButton.js +++ b/src/account-info/SwitchAccountButton.js @@ -1,10 +1,9 @@ /* @flow */ import React, { PureComponent } from 'react'; import { StyleSheet } from 'react-native'; -import { connect } from 'react-redux'; import type { Auth, Actions } from '../types'; -import boundActions from '../boundActions'; +import connectWithActions from '../connectWithActions'; import { ZulipButton } from '../common'; import { getAuth } from '../selectors'; import unregisterPush from '../api/unregisterPush'; @@ -50,11 +49,8 @@ class SwitchAccountButton extends PureComponent { } } -export default connect( - state => ({ - auth: getAuth(state), - accounts: state.accounts, - pushToken: state.realm.pushToken, - }), - boundActions, -)(SwitchAccountButton); +export default connectWithActions(state => ({ + auth: getAuth(state), + accounts: state.accounts, + pushToken: state.realm.pushToken, +}))(SwitchAccountButton); diff --git a/src/account/AccountPickScreen.js b/src/account/AccountPickScreen.js index 38137c8bf0a..fb67b0b0335 100644 --- a/src/account/AccountPickScreen.js +++ b/src/account/AccountPickScreen.js @@ -1,10 +1,9 @@ /* @flow */ import React, { PureComponent } from 'react'; import { StyleSheet } from 'react-native'; -import { connect } from 'react-redux'; import type { Auth, Actions } from '../types'; -import boundActions from '../boundActions'; +import connectWithActions from '../connectWithActions'; import { getAuth } from '../selectors'; import { Centerer, ZulipButton, Logo, Screen } from '../common'; import AccountList from './AccountList'; @@ -60,10 +59,7 @@ class AccountPickScreen extends PureComponent { } } -export default connect( - state => ({ - auth: getAuth(state), - accounts: state.accounts, - }), - boundActions, -)(AccountPickScreen); +export default connectWithActions(state => ({ + auth: getAuth(state), + accounts: state.accounts, +}))(AccountPickScreen); diff --git a/src/autocomplete/PeopleAutocomplete.js b/src/autocomplete/PeopleAutocomplete.js index c913f34667f..6142ea3a0f0 100644 --- a/src/autocomplete/PeopleAutocomplete.js +++ b/src/autocomplete/PeopleAutocomplete.js @@ -1,9 +1,9 @@ /* @flow */ import React, { PureComponent } from 'react'; import { FlatList } from 'react-native'; -import { connect } from 'react-redux'; import type { User, GlobalState } from '../types'; +import connectWithActions from '../connectWithActions'; import { getOwnEmail, sortAlphabetically, @@ -51,7 +51,7 @@ class PeopleAutocomplete extends PureComponent { } } -export default connect((state: GlobalState) => ({ +export default connectWithActions((state: GlobalState) => ({ ownEmail: getOwnEmail(state), users: sortAlphabetically(getAllActiveUsers(state)), }))(PeopleAutocomplete); diff --git a/src/autocomplete/StreamAutocomplete.js b/src/autocomplete/StreamAutocomplete.js index 3d0ddf91c7f..60dc094da3f 100644 --- a/src/autocomplete/StreamAutocomplete.js +++ b/src/autocomplete/StreamAutocomplete.js @@ -1,9 +1,9 @@ /* @flow */ import React, { PureComponent } from 'react'; import { FlatList } from 'react-native'; -import { connect } from 'react-redux'; import type { GlobalState, SubscriptionsState } from '../types'; +import connectWithActions from '../connectWithActions'; import { Popup } from '../common'; import { getSubscribedStreams } from '../subscriptions/subscriptionSelectors'; import StreamItem from '../streams/StreamItem'; @@ -48,6 +48,6 @@ class StreamAutocomplete extends PureComponent { } } -export default connect((state: GlobalState) => ({ +export default connectWithActions((state: GlobalState) => ({ subscriptions: getSubscribedStreams(state), }))(StreamAutocomplete); diff --git a/src/boot/AppDataFetcher.js b/src/boot/AppDataFetcher.js index fc429bcedc4..e8e8e6a5c67 100644 --- a/src/boot/AppDataFetcher.js +++ b/src/boot/AppDataFetcher.js @@ -1,9 +1,8 @@ /* @flow */ import { PureComponent } from 'react'; -import { connect } from 'react-redux'; import { Actions } from '../types'; -import boundActions from '../boundActions'; +import connectWithActions from '../connectWithActions'; type Props = { needsInitialFetch: boolean, @@ -31,9 +30,6 @@ class AppDataFetcher extends PureComponent { } } -export default connect( - state => ({ - needsInitialFetch: state.app.needsInitialFetch, - }), - boundActions, -)(AppDataFetcher); +export default connectWithActions(state => ({ + needsInitialFetch: state.app.needsInitialFetch, +}))(AppDataFetcher); diff --git a/src/boot/AppEventHandlers.js b/src/boot/AppEventHandlers.js index d605a975073..8c24df599d9 100644 --- a/src/boot/AppEventHandlers.js +++ b/src/boot/AppEventHandlers.js @@ -1,11 +1,10 @@ /* @flow */ import React, { PureComponent } from 'react'; import { AppState, BackHandler, NetInfo, View, Platform } from 'react-native'; -import { connect } from 'react-redux'; import SafeArea from 'react-native-safe-area'; import { Auth, Actions } from '../types'; -import boundActions from '../boundActions'; +import connectWithActions from '../connectWithActions'; import { getAuth, getNavigationIndex } from '../selectors'; import { registerAppActivity } from '../utils/activity'; import { handlePendingNotifications } from '../utils/notifications'; @@ -93,11 +92,8 @@ class AppEventHandlers extends PureComponent { } } -export default connect( - state => ({ - auth: getAuth(state), - needsInitialFetch: state.app.needsInitialFetch, - navIndex: getNavigationIndex(state), - }), - boundActions, -)(AppEventHandlers); +export default connectWithActions(state => ({ + auth: getAuth(state), + needsInitialFetch: state.app.needsInitialFetch, + navIndex: getNavigationIndex(state), +}))(AppEventHandlers); diff --git a/src/boot/StylesProvider.js b/src/boot/StylesProvider.js index 23602320d25..44a0a562b5c 100644 --- a/src/boot/StylesProvider.js +++ b/src/boot/StylesProvider.js @@ -1,8 +1,8 @@ /* @flow */ import React, { PureComponent } from 'react'; import { StyleSheet } from 'react-native'; -import { connect } from 'react-redux'; +import connectWithActions from '../connectWithActions'; import themeCreator from '../styles/theme'; import themeDark from '../styles/themeDark'; import themeLight from '../styles/themeLight'; @@ -45,6 +45,6 @@ class StyleProvider extends PureComponent { } } -export default connect(state => ({ +export default connectWithActions(state => ({ theme: state.settings.theme, }))(StyleProvider); diff --git a/src/boot/TranslationProvider.js b/src/boot/TranslationProvider.js index 17cee0abda7..87f004ed9a0 100644 --- a/src/boot/TranslationProvider.js +++ b/src/boot/TranslationProvider.js @@ -1,9 +1,9 @@ /* @flow */ import React, { PureComponent } from 'react'; import { Text } from 'react-native'; -import { connect } from 'react-redux'; import { IntlProvider } from 'react-intl'; +import connectWithActions from '../connectWithActions'; import '../../vendor/intl/intl'; import messages from '../i18n/messages'; @@ -26,6 +26,6 @@ class TranslationProvider extends PureComponent { } } -export default connect(state => ({ +export default connectWithActions(state => ({ locale: state.settings.locale, }))(TranslationProvider); diff --git a/src/boundActions.js b/src/boundActions.js deleted file mode 100644 index 4c50bcdb359..00000000000 --- a/src/boundActions.js +++ /dev/null @@ -1,18 +0,0 @@ -/* @flow */ -import { bindActionCreators } from 'redux'; -import type { MapStateToProps } from 'react-redux'; - -import type { Dispatch } from './types'; -import * as actions from './actions'; - -let cachedBoundActions: MapStateToProps<*, *, *>; - -export default (dispatch: Dispatch, ownProps: Object): MapStateToProps<*, *, *> => { - if (!cachedBoundActions) { - cachedBoundActions = { - actions: bindActionCreators(actions, dispatch), - }; - } - - return cachedBoundActions; -}; diff --git a/src/chat/ChatContainer.js b/src/chat/ChatContainer.js index 871f16ec867..cafe278b33b 100644 --- a/src/chat/ChatContainer.js +++ b/src/chat/ChatContainer.js @@ -1,16 +1,11 @@ /* @flow */ -import { connect } from 'react-redux'; - -import boundActions from '../boundActions'; +import connectWithActions from '../connectWithActions'; import { getActiveNarrow, getIsFetching, getIfNoMessages } from '../selectors'; import Chat from './Chat'; -export default connect( - state => ({ - isOnline: state.app.isOnline, - isFetching: getIsFetching(state), - narrow: getActiveNarrow(state), - noMessages: getIfNoMessages(state), - }), - boundActions, -)(Chat); +export default connectWithActions(state => ({ + isOnline: state.app.isOnline, + isFetching: getIsFetching(state), + narrow: getActiveNarrow(state), + noMessages: getIfNoMessages(state), +}))(Chat); diff --git a/src/chat/GroupDetailsScreen.js b/src/chat/GroupDetailsScreen.js index d04abf09058..5562b5562a7 100644 --- a/src/chat/GroupDetailsScreen.js +++ b/src/chat/GroupDetailsScreen.js @@ -1,10 +1,9 @@ /* @flow */ import React, { PureComponent } from 'react'; -import { connect } from 'react-redux'; import { View, FlatList, StyleSheet } from 'react-native'; import type { Actions } from '../types'; -import boundActions from '../boundActions'; +import connectWithActions from '../connectWithActions'; import { Screen, Label } from '../common'; import UserItem from '../users/UserItem'; import { BRAND_COLOR } from '../styles'; @@ -69,4 +68,4 @@ class GroupDetailsScreen extends PureComponent { } } -export default connect(null, boundActions)(GroupDetailsScreen); +export default connectWithActions(null)(GroupDetailsScreen); diff --git a/src/chat/MarkUnreadButton.js b/src/chat/MarkUnreadButton.js index 18af3d51003..e7787b48c8c 100644 --- a/src/chat/MarkUnreadButton.js +++ b/src/chat/MarkUnreadButton.js @@ -1,9 +1,9 @@ /* @flow */ import React, { PureComponent } from 'react'; import { StyleSheet } from 'react-native'; -import { connect } from 'react-redux'; import type { Auth, Narrow, Stream } from '../types'; +import connectWithActions from '../connectWithActions'; import { ZulipButton } from '../common'; import { markAllAsRead, markStreamAsRead, markTopicAsRead } from '../api'; import { getActiveNarrow, getAuth, getStreams } from '../selectors'; @@ -85,7 +85,7 @@ class MarkUnreadButton extends PureComponent { } } -export default connect(state => ({ +export default connectWithActions(state => ({ auth: getAuth(state), narrow: getActiveNarrow(state), streams: getStreams(state), diff --git a/src/chat/UnreadNoticeContainer.js b/src/chat/UnreadNoticeContainer.js index 980fd393d58..888a9bc9270 100644 --- a/src/chat/UnreadNoticeContainer.js +++ b/src/chat/UnreadNoticeContainer.js @@ -1,13 +1,8 @@ /* @flow */ -import { connect } from 'react-redux'; - -import boundActions from '../boundActions'; +import connectWithActions from '../connectWithActions'; import { getUnreadCountInActiveNarrow } from '../selectors'; import UnreadNotice from './UnreadNotice'; -export default connect( - state => ({ - unreadCount: getUnreadCountInActiveNarrow(state), - }), - boundActions, -)(UnreadNotice); +export default connectWithActions(state => ({ + unreadCount: getUnreadCountInActiveNarrow(state), +}))(UnreadNotice); diff --git a/src/common/Avatar.js b/src/common/Avatar.js index dda7ec18671..1d46e2517cb 100644 --- a/src/common/Avatar.js +++ b/src/common/Avatar.js @@ -1,9 +1,9 @@ /* @flow */ import React, { PureComponent } from 'react'; import { StyleSheet } from 'react-native'; -import { connect } from 'react-redux'; import type { Presence } from '../types'; +import connectWithActions from '../connectWithActions'; import { nullFunction, NULL_PRESENCE } from '../nullObjects'; import { getCurrentRealm } from '../selectors'; import ImageAvatar from './ImageAvatar'; @@ -59,6 +59,6 @@ class Avatar extends PureComponent { } } -export default connect(state => ({ +export default connectWithActions(state => ({ realm: getCurrentRealm(state), }))(Avatar); diff --git a/src/common/Screen.js b/src/common/Screen.js index e825e8d5667..a9350fa968e 100644 --- a/src/common/Screen.js +++ b/src/common/Screen.js @@ -1,9 +1,9 @@ /* @flow */ import React, { PureComponent } from 'react'; import { ScrollView, StyleSheet, View } from 'react-native'; -import { connect } from 'react-redux'; import type { Dimensions, LocalizableText } from '../types'; +import connectWithActions from '../connectWithActions'; import { KeyboardAvoider, ZulipStatusBar } from '../common'; import ModalNavBar from '../nav/ModalNavBar'; import ModalSearchNavBar from '../nav/ModalSearchNavBar'; @@ -64,6 +64,6 @@ class Screen extends PureComponent { } } -export default connect((state, props) => ({ +export default connectWithActions((state, props) => ({ safeAreaInsets: state.app.safeAreaInsets, }))(Screen); diff --git a/src/common/WebLink.js b/src/common/WebLink.js index 4062350d2d3..695ed1ebbbf 100644 --- a/src/common/WebLink.js +++ b/src/common/WebLink.js @@ -1,7 +1,7 @@ /* @flow */ import React, { PureComponent } from 'react'; -import { connect } from 'react-redux'; +import connectWithActions from '../connectWithActions'; import { Touchable, Label } from '../common'; import { getFullUrl } from '../utils/url'; import openLink from '../utils/openLink'; @@ -37,6 +37,6 @@ class WebLink extends PureComponent { } } -export default connect(state => ({ +export default connectWithActions(state => ({ realm: getCurrentRealm(state), }))(WebLink); diff --git a/src/common/ZulipStatusBar.js b/src/common/ZulipStatusBar.js index 0cfa490d3a6..a53135dddf5 100644 --- a/src/common/ZulipStatusBar.js +++ b/src/common/ZulipStatusBar.js @@ -1,10 +1,10 @@ /* @flow */ import React, { PureComponent } from 'react'; import { Platform, StatusBar, View } from 'react-native'; -import { connect } from 'react-redux'; import Color from 'color'; import type { Dimensions, StatusBarStyle } from '../types'; +import connectWithActions from '../connectWithActions'; import { getTitleBackgroundColor, getTitleTextColor } from '../selectors'; import getStatusBarStyle from '../utils/getStatusBarStyle'; import getStatusBarColor from '../utils/getStatusBarColor'; @@ -50,7 +50,7 @@ class ZulipStatusBar extends PureComponent { } } -export default connect((state, props) => ({ +export default connectWithActions((state, props) => ({ safeAreaInsets: state.app.safeAreaInsets, theme: state.settings.theme, backgroundColor: !props.backgroundColor ? getTitleBackgroundColor(state) : props.backgroundColor, diff --git a/src/compose/ComposeBoxContainer.js b/src/compose/ComposeBoxContainer.js index 04744a61ce9..784e385e4fe 100644 --- a/src/compose/ComposeBoxContainer.js +++ b/src/compose/ComposeBoxContainer.js @@ -1,25 +1,20 @@ /* @flow */ -import { connect } from 'react-redux'; - import type { GlobalState } from '../types'; -import boundActions from '../boundActions'; +import connectWithActions from '../connectWithActions'; import { getAuth, getLastTopicInActiveNarrow, canSendToActiveNarrow } from '../selectors'; import { getIsActiveStreamSubscribed } from '../subscriptions/subscriptionSelectors'; import { getDraftForActiveNarrow } from '../drafts/draftsSelectors'; import ComposeBox from './ComposeBox'; -export default connect( - (state: GlobalState) => ({ - auth: getAuth(state), - narrow: state.chat.narrow, - users: state.users, - safeAreaInsets: state.app.safeAreaInsets, - composeTools: state.app.composeTools, - lastTopic: getLastTopicInActiveNarrow(state), - isSubscribed: getIsActiveStreamSubscribed(state), - canSend: canSendToActiveNarrow(state), - editMessage: state.app.editMessage, - draft: getDraftForActiveNarrow(state), - }), - boundActions, -)(ComposeBox); +export default connectWithActions((state: GlobalState) => ({ + auth: getAuth(state), + narrow: state.chat.narrow, + users: state.users, + safeAreaInsets: state.app.safeAreaInsets, + composeTools: state.app.composeTools, + lastTopic: getLastTopicInActiveNarrow(state), + isSubscribed: getIsActiveStreamSubscribed(state), + canSend: canSendToActiveNarrow(state), + editMessage: state.app.editMessage, + draft: getDraftForActiveNarrow(state), +}))(ComposeBox); diff --git a/src/compose/ComposeMenuContainer.js b/src/compose/ComposeMenuContainer.js index e50a39bbdac..e8ac72a97cd 100644 --- a/src/compose/ComposeMenuContainer.js +++ b/src/compose/ComposeMenuContainer.js @@ -1,10 +1,9 @@ /* @flow */ import React from 'react'; import { StyleSheet, View } from 'react-native'; -import { connect } from 'react-redux'; import { connectActionSheet } from '@expo/react-native-action-sheet'; -import boundActions from '../boundActions'; +import connectWithActions from '../connectWithActions'; import ComposeMenu from './ComposeMenu'; import { getActiveNarrow } from '../selectors'; @@ -16,12 +15,9 @@ const componentStyles = StyleSheet.create({ }, }); -export default connect( - state => ({ - narrow: getActiveNarrow(state), - }), - boundActions, -)(props => ( +export default connectWithActions(state => ({ + narrow: getActiveNarrow(state), +}))(props => ( diff --git a/src/connectWithActions.js b/src/connectWithActions.js new file mode 100644 index 00000000000..5cdfc22c7f6 --- /dev/null +++ b/src/connectWithActions.js @@ -0,0 +1,22 @@ +/* @flow */ +import { bindActionCreators } from 'redux'; +import { connect } from 'react-redux'; +import type { Dispatch, MapStateToProps } from 'react-redux'; + +// import type { Dispatch } from './types'; +import * as actions from './actions'; + +let cachedBoundActions; + +const boundActions = (dispatch: Dispatch, ownProps: Object) => { + if (!cachedBoundActions) { + cachedBoundActions = { + actions: bindActionCreators(actions, dispatch), + }; + } + + return cachedBoundActions; +}; + +export default (mapStateToProps: MapStateToProps) => (component: React$Component) => + connect(mapStateToProps, boundActions)(component); diff --git a/src/conversations/ConversationGroup.js b/src/conversations/ConversationGroup.js index 13eac32ba2d..82ff9592d0f 100644 --- a/src/conversations/ConversationGroup.js +++ b/src/conversations/ConversationGroup.js @@ -1,9 +1,8 @@ /* @flow */ import React, { PureComponent } from 'react'; import { StyleSheet, View } from 'react-native'; -import { connect } from 'react-redux'; -import boundActions from '../boundActions'; +import connectWithActions from '../connectWithActions'; import { NULL_USER } from '../nullObjects'; import type { User, Narrow } from '../types'; import { normalizeRecipients } from '../utils/message'; @@ -73,10 +72,7 @@ class ConversationGroup extends PureComponent { } } -export default connect( - state => ({ - narrow: state.chat.narrow, - users: state.users, - }), - boundActions, -)(ConversationGroup); +export default connectWithActions(state => ({ + narrow: state.chat.narrow, + users: state.users, +}))(ConversationGroup); diff --git a/src/conversations/ConversationUser.js b/src/conversations/ConversationUser.js index 07ff8cda657..d69a7551f7b 100644 --- a/src/conversations/ConversationUser.js +++ b/src/conversations/ConversationUser.js @@ -1,8 +1,7 @@ /* @flow */ import React, { PureComponent } from 'react'; -import { connect } from 'react-redux'; -import boundActions from '../boundActions'; +import connectWithActions from '../connectWithActions'; import type { Narrow, User } from '../types'; import { getAllActiveUsers } from '../selectors'; import UserItem from '../users/UserItem'; @@ -43,10 +42,7 @@ class ConversationUser extends PureComponent { } } -export default connect( - state => ({ - narrow: state.chat.narrow, - users: getAllActiveUsers(state), - }), - boundActions, -)(ConversationUser); +export default connectWithActions(state => ({ + narrow: state.chat.narrow, + users: getAllActiveUsers(state), +}))(ConversationUser); diff --git a/src/conversations/ConversationsContainer.js b/src/conversations/ConversationsContainer.js index 9ac19de2a05..1d899d525c2 100644 --- a/src/conversations/ConversationsContainer.js +++ b/src/conversations/ConversationsContainer.js @@ -1,13 +1,8 @@ /* @flow */ -import { connect } from 'react-redux'; - -import boundActions from '../boundActions'; +import connectWithActions from '../connectWithActions'; import { getRecentConversations } from '../selectors'; import ConversationsCard from './ConversationsCard'; -export default connect( - state => ({ - conversations: getRecentConversations(state), - }), - boundActions, -)(ConversationsCard); +export default connectWithActions(state => ({ + conversations: getRecentConversations(state), +}))(ConversationsCard); diff --git a/src/diagnostics/DiagnosticsScreen.js b/src/diagnostics/DiagnosticsScreen.js index f257ce7a33d..a6d34534820 100644 --- a/src/diagnostics/DiagnosticsScreen.js +++ b/src/diagnostics/DiagnosticsScreen.js @@ -1,10 +1,9 @@ /* @flow */ import React, { PureComponent } from 'react'; import { StyleSheet, View } from 'react-native'; -import { connect } from 'react-redux'; import type { Actions } from '../types'; -import boundActions from '../boundActions'; +import connectWithActions from '../connectWithActions'; import { Screen } from '../common'; import OptionButton from '../settings/OptionButton'; @@ -36,4 +35,4 @@ class DiagnosticsScreen extends PureComponent { } } -export default connect(null, boundActions)(DiagnosticsScreen); +export default connectWithActions(null)(DiagnosticsScreen); diff --git a/src/diagnostics/StorageScreen.js b/src/diagnostics/StorageScreen.js index 0fc0769d300..33ba853a45c 100644 --- a/src/diagnostics/StorageScreen.js +++ b/src/diagnostics/StorageScreen.js @@ -1,9 +1,9 @@ /* @flow */ import React, { PureComponent } from 'react'; import { FlatList } from 'react-native'; -import { connect } from 'react-redux'; import type { GlobalState } from '../types'; +import connectWithActions from '../connectWithActions'; import { Screen } from '../common'; import SizeItem from './SizeItem'; @@ -38,6 +38,6 @@ class StorageScreen extends PureComponent { } } -export default connect(state => ({ +export default connectWithActions(state => ({ state, }))(StorageScreen); diff --git a/src/emoji/RealmEmoji.js b/src/emoji/RealmEmoji.js index db450a39a70..ea6cef0c08f 100644 --- a/src/emoji/RealmEmoji.js +++ b/src/emoji/RealmEmoji.js @@ -1,9 +1,9 @@ /* @flow */ import React, { PureComponent } from 'react'; import { StyleSheet, Image } from 'react-native'; -import { connect } from 'react-redux'; import type { Auth } from '../types'; +import connectWithActions from '../connectWithActions'; import { getAuth } from '../selectors'; const styles = StyleSheet.create({ @@ -34,7 +34,7 @@ class RealmEmoji extends PureComponent { } } -export default connect(state => ({ +export default connectWithActions(state => ({ auth: getAuth(state), realmEmoji: state.realm.emoji, }))(RealmEmoji); diff --git a/src/group/GroupContainer.js b/src/group/GroupContainer.js index 2886ac29fab..b2ceee8506c 100644 --- a/src/group/GroupContainer.js +++ b/src/group/GroupContainer.js @@ -1,15 +1,10 @@ /* @flow */ -import { connect } from 'react-redux'; - import { getOwnEmail, getAllActiveUsers, getPresence } from '../selectors'; -import boundActions from '../boundActions'; +import connectWithActions from '../connectWithActions'; import GroupCard from './GroupCard'; -export default connect( - state => ({ - ownEmail: getOwnEmail(state), - users: getAllActiveUsers(state), - presences: getPresence(state), - }), - boundActions, -)(GroupCard); +export default connectWithActions(state => ({ + ownEmail: getOwnEmail(state), + users: getAllActiveUsers(state), + presences: getPresence(state), +}))(GroupCard); diff --git a/src/html/HtmlNodeTag.js b/src/html/HtmlNodeTag.js index 354750b69f3..0aac7c37b03 100644 --- a/src/html/HtmlNodeTag.js +++ b/src/html/HtmlNodeTag.js @@ -1,8 +1,8 @@ /* @flow */ import React, { PureComponent } from 'react'; -import { connect } from 'react-redux'; import type { Auth, Message, Actions, StyleObj, SupportedHtmlClasses } from '../types'; +import connectWithActions from '../connectWithActions'; import styles from './HtmlStyles'; import cascadingStyles from './cascadingStylesView'; import cascadingStylesText from './cascadingStylesText'; @@ -116,9 +116,6 @@ class HtmlNodeTag extends PureComponent { } } -export default connect( - state => ({ - ownEmail: getOwnEmail(state), - }), - {}, -)(HtmlNodeTag); +export default connectWithActions(state => ({ + ownEmail: getOwnEmail(state), +}))(HtmlNodeTag); diff --git a/src/lightbox/LightboxContainer.js b/src/lightbox/LightboxContainer.js index a26d9b8042e..451dec4ec55 100644 --- a/src/lightbox/LightboxContainer.js +++ b/src/lightbox/LightboxContainer.js @@ -1,15 +1,14 @@ /* @flow */ import React, { PureComponent } from 'react'; import { View, StyleSheet, Dimensions, Easing } from 'react-native'; -import { connect } from 'react-redux'; import PhotoView from 'react-native-photo-view'; import { connectActionSheet } from '@expo/react-native-action-sheet'; -import type { Actions, Auth, Message, ImageResource, Connector } from '../types'; +import type { Actions, Auth, Message, ImageResource } from '../types'; +import connectWithActions from '../connectWithActions'; import { getAuth } from '../selectors'; import LightboxHeader from './LightboxHeader'; import LightboxFooter from './LightboxFooter'; -import boundActions from '../boundActions'; import { constructActionSheetButtons, executeActionSheetAction } from './LightboxActionSheet'; import { NAVBAR_HEIGHT, LIGHTBOX_FOOTER_OFFSET, LIGHTBOX_OVERLAY_COLOR } from '../styles'; @@ -145,11 +144,10 @@ class LightboxContainer extends PureComponent { } } -const connector: Connector> = connect( - state => ({ - auth: getAuth(state), - }), - boundActions, +export default connectActionSheet( + connectWithActions(state => + ({ + auth: getAuth(state), + }(LightboxContainer)), + ), ); - -export default connectActionSheet(connector(LightboxContainer)); diff --git a/src/message/MessageContainer.js b/src/message/MessageContainer.js index 91fa17a3cc7..287c858950f 100644 --- a/src/message/MessageContainer.js +++ b/src/message/MessageContainer.js @@ -1,6 +1,5 @@ /* @flow */ import React, { PureComponent } from 'react'; -import { connect } from 'react-redux'; import { connectActionSheet } from '@expo/react-native-action-sheet'; import type { Actions, Auth, SubscriptionsState, Narrow, Message } from '../types'; @@ -13,7 +12,7 @@ import { getCurrentRoute, getActiveNarrow, } from '../selectors'; -import boundActions from '../boundActions'; +import connectWithActions from '../connectWithActions'; import { constructActionButtons, executeActionSheetAction } from './messageActionSheet'; import type { ShowActionSheetTypes } from './messageActionSheet'; @@ -113,14 +112,11 @@ class MessageContainer extends PureComponent { } } -export default connect( - state => ({ - auth: getAuth(state), - narrow: getActiveNarrow(state), - currentRoute: getCurrentRoute(state), - flags: getFlags(state), - twentyFourHourTime: state.realm.twentyFourHourTime, - subscriptions: getSubscriptions(state), - }), - boundActions, -)(connectActionSheet(MessageContainer)); +export default connectWithActions(state => ({ + auth: getAuth(state), + narrow: getActiveNarrow(state), + currentRoute: getCurrentRoute(state), + flags: getFlags(state), + twentyFourHourTime: state.realm.twentyFourHourTime, + subscriptions: getSubscriptions(state), +}))(connectActionSheet(MessageContainer)); diff --git a/src/message/MessageListContainer.js b/src/message/MessageListContainer.js index 3522136f582..2840b9a72f3 100644 --- a/src/message/MessageListContainer.js +++ b/src/message/MessageListContainer.js @@ -1,10 +1,8 @@ import React, { PureComponent } from 'react'; - -import { connect } from 'react-redux'; import { connectActionSheet } from '@expo/react-native-action-sheet'; import type { Actions, Fetching, Narrow } from '../types'; -import boundActions from '../boundActions'; +import connectWithActions from '../connectWithActions'; import MessageList from './MessageList'; // import MessageList from './MessageListFlatList'; import { @@ -82,15 +80,12 @@ class MessageListContainer extends PureComponent { } } -export default connect( - state => ({ - caughtUp: getCaughtUpForActiveNarrow(state), - fetching: getFetchingForActiveNarrow(state), - typingUsers: getCurrentTypingUsers(state), - renderedMessages: getRenderedMessages(state), - narrow: getActiveNarrow(state), - auth: getAuth(state), - flags: getFlags(state), - }), - boundActions, -)(connectActionSheet(MessageListContainer)); +export default connectWithActions(state => ({ + caughtUp: getCaughtUpForActiveNarrow(state), + fetching: getFetchingForActiveNarrow(state), + typingUsers: getCurrentTypingUsers(state), + renderedMessages: getRenderedMessages(state), + narrow: getActiveNarrow(state), + auth: getAuth(state), + flags: getFlags(state), +}))(connectActionSheet(MessageListContainer)); diff --git a/src/message/NotSubscribed.js b/src/message/NotSubscribed.js index 0d38b09caa0..4fbfc69fe09 100644 --- a/src/message/NotSubscribed.js +++ b/src/message/NotSubscribed.js @@ -1,10 +1,9 @@ /* @flow */ import React, { PureComponent } from 'react'; import { StyleSheet, View } from 'react-native'; -import { connect } from 'react-redux'; import type { Auth, Narrow, Stream } from '../types'; -import boundActions from '../boundActions'; +import connectWithActions from '../connectWithActions'; import { subscriptionAdd } from '../api'; import { ZulipButton, Label } from '../common'; import { getAuth, getActiveNarrow } from '../selectors'; @@ -56,11 +55,8 @@ class NotSubscribed extends PureComponent { } } -export default connect( - state => ({ - auth: getAuth(state), - narrow: getActiveNarrow(state), - streams: state.streams, - }), - boundActions, -)(NotSubscribed); +export default connectWithActions(state => ({ + auth: getAuth(state), + narrow: getActiveNarrow(state), + streams: state.streams, +}))(NotSubscribed); diff --git a/src/message/headers/MessageHeaderContainer.js b/src/message/headers/MessageHeaderContainer.js index d8243c8b372..8032bd79b71 100644 --- a/src/message/headers/MessageHeaderContainer.js +++ b/src/message/headers/MessageHeaderContainer.js @@ -1,17 +1,13 @@ /* @flow */ -import { connect } from 'react-redux'; import { connectActionSheet } from '@expo/react-native-action-sheet'; +import connectWithActions from '../../connectWithActions'; import MessageHeader from './MessageHeader'; -import boundActions from '../../boundActions'; import { getAuth, getActiveNarrow, getSubscriptions } from '../../selectors'; -export default connect( - state => ({ - auth: getAuth(state), - narrow: getActiveNarrow(state), - subscriptions: getSubscriptions(state), - mute: state.mute, - }), - boundActions, -)(connectActionSheet(MessageHeader)); +export default connectWithActions(state => ({ + auth: getAuth(state), + narrow: getActiveNarrow(state), + subscriptions: getSubscriptions(state), + mute: state.mute, +}))(connectActionSheet(MessageHeader)); diff --git a/src/nav/AppWithNavigationState.js b/src/nav/AppWithNavigationState.js index ac2b0eb2c39..9fd4a8ed7db 100644 --- a/src/nav/AppWithNavigationState.js +++ b/src/nav/AppWithNavigationState.js @@ -1,11 +1,11 @@ /* TODO flow */ import React from 'react'; import { addNavigationHelpers } from 'react-navigation'; -import { connect } from 'react-redux'; +import connectWithActions from '../connectWithActions'; import AppNavigator from './AppNavigator'; -export default connect(state => ({ +export default connectWithActions(state => ({ nav: state.nav, }))(props => ( ({ - unreadHuddlesTotal: getUnreadHuddlesTotal(state), - unreadPmsTotal: getUnreadPmsTotal(state), - }), - boundActions, -)(IconUnreadConversations); +export default connectWithActions(state => ({ + unreadHuddlesTotal: getUnreadHuddlesTotal(state), + unreadPmsTotal: getUnreadPmsTotal(state), +}))(IconUnreadConversations); diff --git a/src/nav/MainNavBar.js b/src/nav/MainNavBar.js index d0b2df32927..54cd95d639c 100644 --- a/src/nav/MainNavBar.js +++ b/src/nav/MainNavBar.js @@ -1,10 +1,9 @@ /* @flow */ import React, { PureComponent } from 'react'; -import { connect } from 'react-redux'; import { View } from 'react-native'; import type { Actions } from '../types'; -import boundActions from '../boundActions'; +import connectWithActions from '../connectWithActions'; import Title from '../title/Title'; import NavButton from './NavButton'; import NavButtonPlaceholder from './NavButtonPlaceholder'; @@ -60,14 +59,11 @@ class MainNavBar extends PureComponent { } } -export default connect( - state => ({ - backgroundColor: getTitleBackgroundColor(state), - textColor: getTitleTextColor(state), - unreadHuddlesTotal: getUnreadHuddlesTotal(state), - unreadMentionsTotal: getUnreadMentionsTotal(state), - unreadPmsTotal: getUnreadPmsTotal(state), - editMessage: state.app.editMessage, - }), - boundActions, -)(MainNavBar); +export default connectWithActions(state => ({ + backgroundColor: getTitleBackgroundColor(state), + textColor: getTitleTextColor(state), + unreadHuddlesTotal: getUnreadHuddlesTotal(state), + unreadMentionsTotal: getUnreadMentionsTotal(state), + unreadPmsTotal: getUnreadPmsTotal(state), + editMessage: state.app.editMessage, +}))(MainNavBar); diff --git a/src/nav/ModalNavBar.js b/src/nav/ModalNavBar.js index 321aae5e3f9..dd40df2c20a 100644 --- a/src/nav/ModalNavBar.js +++ b/src/nav/ModalNavBar.js @@ -1,10 +1,9 @@ /* @flow */ import React, { PureComponent, Children } from 'react'; import { View, StyleSheet } from 'react-native'; -import { connect } from 'react-redux'; -import type { Actions, LocalizableText, StyleObj, Connector } from '../types'; -import boundActions from '../boundActions'; +import type { Actions, LocalizableText, StyleObj } from '../types'; +import connectWithActions from '../connectWithActions'; import { CONTROL_SIZE } from '../styles'; import { Label } from '../common'; import NavButton from './NavButton'; @@ -77,11 +76,6 @@ class ModalNavBar extends PureComponent { } } -const connector: Connector = connect( - state => ({ - nav: state.nav, - }), - boundActions, -); - -export default connector(ModalNavBar); +export default connectWithActions(state => ({ + nav: state.nav, +}))(ModalNavBar); diff --git a/src/nav/ModalSearchNavBar.js b/src/nav/ModalSearchNavBar.js index 9de4f9cccc4..49db9af9cf9 100644 --- a/src/nav/ModalSearchNavBar.js +++ b/src/nav/ModalSearchNavBar.js @@ -1,10 +1,9 @@ /* @flow */ import React, { PureComponent } from 'react'; import { View, StyleSheet } from 'react-native'; -import { connect } from 'react-redux'; import type { Actions } from '../types'; -import boundActions from '../boundActions'; +import connectWithActions from '../connectWithActions'; import { CONTROL_SIZE } from '../styles'; import { Label, SearchInput } from '../common'; import NavButton from './NavButton'; @@ -88,9 +87,6 @@ class ModalSearchNavBar extends PureComponent { } } -export default connect( - state => ({ - nav: state.nav, - }), - boundActions, -)(ModalSearchNavBar); +export default connectWithActions(state => ({ + nav: state.nav, +}))(ModalSearchNavBar); diff --git a/src/nav/Sidebar.js b/src/nav/Sidebar.js index 373c4ccf37f..f49ff171cef 100644 --- a/src/nav/Sidebar.js +++ b/src/nav/Sidebar.js @@ -1,10 +1,9 @@ /* @flow */ import React, { PureComponent } from 'react'; import { StyleSheet, View } from 'react-native'; -import { connect } from 'react-redux'; import type { Dimensions, Narrow } from '../types'; -import boundActions from '../boundActions'; +import connectWithActions from '../connectWithActions'; import MainTabs from '../main/MainTabs'; const componentStyles = StyleSheet.create({ @@ -55,9 +54,6 @@ class Sidebar extends PureComponent { } } -export default connect( - state => ({ - safeAreaInsets: state.app.safeAreaInsets, - }), - boundActions, -)(Sidebar); +export default connectWithActions(state => ({ + safeAreaInsets: state.app.safeAreaInsets, +}))(Sidebar); diff --git a/src/nav/StreamTabsCard.js b/src/nav/StreamTabsCard.js index 91e05f1c723..68563acc378 100644 --- a/src/nav/StreamTabsCard.js +++ b/src/nav/StreamTabsCard.js @@ -1,9 +1,8 @@ /* @flow */ import React, { PureComponent } from 'react'; import { StyleSheet, View } from 'react-native'; -import { connect } from 'react-redux'; -import boundActions from '../boundActions'; +import connectWithActions from '../connectWithActions'; import type { Actions, Narrow } from '../types'; import { homeNarrow, specialNarrow, allPrivateNarrow } from '../utils/narrow'; import NavButton from './NavButton'; @@ -45,4 +44,4 @@ class StreamTabsCard extends PureComponent { } } -export default connect(null, boundActions)(StreamTabsCard); +export default connectWithActions(null)(StreamTabsCard); diff --git a/src/reactions/Reaction.js b/src/reactions/Reaction.js index 675460d4498..497a98597d9 100644 --- a/src/reactions/Reaction.js +++ b/src/reactions/Reaction.js @@ -1,9 +1,9 @@ /* @flow */ import React, { PureComponent } from 'react'; import { StyleSheet, Text, View, Animated, Easing } from 'react-native'; -import { connect } from 'react-redux'; import type { Auth, GlobalState } from '../types'; +import connectWithActions from '../connectWithActions'; import { BRAND_COLOR, HALF_COLOR, REACTION_HEIGHT, REACTION_SPINNER_OFFSET } from '../styles'; import { Touchable } from '../common'; import Emoji from '../emoji/Emoji'; @@ -162,7 +162,7 @@ class Reaction extends PureComponent { } } -export default connect((state: GlobalState) => ({ +export default connectWithActions((state: GlobalState) => ({ auth: getAuth(state), realmEmoji: state.realm.emoji, }))(Reaction); diff --git a/src/search/SearchMessagesContainer.js b/src/search/SearchMessagesContainer.js index fb9bdc5998c..500dc3fe31b 100644 --- a/src/search/SearchMessagesContainer.js +++ b/src/search/SearchMessagesContainer.js @@ -1,13 +1,8 @@ /* @flow */ -import { connect } from 'react-redux'; - -import boundActions from '../boundActions'; +import connectWithActions from '../connectWithActions'; import { getAuth } from '../selectors'; import SearchMessagesCard from './SearchMessagesCard'; -export default connect( - state => ({ - auth: getAuth(state), - }), - boundActions, -)(SearchMessagesCard); +export default connectWithActions(state => ({ + auth: getAuth(state), +}))(SearchMessagesCard); diff --git a/src/settings/LanguageScreen.js b/src/settings/LanguageScreen.js index fc630340829..626e559091b 100644 --- a/src/settings/LanguageScreen.js +++ b/src/settings/LanguageScreen.js @@ -1,11 +1,10 @@ /* @flow */ import React, { PureComponent } from 'react'; -import { connect } from 'react-redux'; import { Actions } from '../types'; import { Screen } from '../common'; import LanguagePicker from './LanguagePicker'; -import boundActions from '../boundActions'; +import connectWithActions from '../connectWithActions'; type Props = { actions: Actions, @@ -31,9 +30,6 @@ class LanguageScreen extends PureComponent { } } -export default connect( - state => ({ - locale: state.settings.locale, - }), - boundActions, -)(LanguageScreen); +export default connectWithActions(state => ({ + locale: state.settings.locale, +}))(LanguageScreen); diff --git a/src/settings/SettingsContainer.js b/src/settings/SettingsContainer.js index ed6d07e3bf7..14131d7c657 100644 --- a/src/settings/SettingsContainer.js +++ b/src/settings/SettingsContainer.js @@ -1,16 +1,11 @@ /* TODO flow */ -import { connect } from 'react-redux'; - -import boundActions from '../boundActions'; +import connectWithActions from '../connectWithActions'; import { getAuth } from '../selectors'; import SettingsCard from './SettingsCard'; -export default connect( - state => ({ - offlineNotification: state.settings.offlineNotification, - onlineNotification: state.settings.onlineNotification, - theme: state.settings.theme, - auth: getAuth(state), - }), - boundActions, -)(SettingsCard); +export default connectWithActions(state => ({ + offlineNotification: state.settings.offlineNotification, + onlineNotification: state.settings.onlineNotification, + theme: state.settings.theme, + auth: getAuth(state), +}))(SettingsCard); diff --git a/src/start/AuthScreen.js b/src/start/AuthScreen.js index 89320d27791..656f2480557 100644 --- a/src/start/AuthScreen.js +++ b/src/start/AuthScreen.js @@ -1,10 +1,9 @@ /* @flow */ import React, { PureComponent } from 'react'; import { View, Image, StyleSheet } from 'react-native'; -import { connect } from 'react-redux'; import { Action, Actions } from '../types'; -import boundActions from '../boundActions'; +import connectWithActions from '../connectWithActions'; import { Centerer, RawLabel, Screen, ZulipButton } from '../common'; import { getCurrentRealm } from '../selectors'; import PasswordAuthView from './PasswordAuthView'; @@ -81,9 +80,6 @@ class AuthScreen extends PureComponent { } } -export default connect( - state => ({ - realm: getCurrentRealm(state), - }), - boundActions, -)(AuthScreen); +export default connectWithActions(state => ({ + realm: getCurrentRealm(state), +}))(AuthScreen); diff --git a/src/start/DevAuthScreen.js b/src/start/DevAuthScreen.js index da30322e96f..765ea66b8eb 100644 --- a/src/start/DevAuthScreen.js +++ b/src/start/DevAuthScreen.js @@ -1,12 +1,9 @@ /* @flow */ import React, { PureComponent } from 'react'; - import { ActivityIndicator, Text, View, StyleSheet, FlatList } from 'react-native'; -import { connect } from 'react-redux'; - import type { Actions, Auth } from '../types'; -import boundActions from '../boundActions'; +import connectWithActions from '../connectWithActions'; import { ErrorMsg, Screen, ZulipButton } from '../common'; import { devGetEmails, devFetchApiKey } from '../api'; import { getAuth } from '../selectors'; @@ -106,9 +103,6 @@ class DevAuthScreen extends PureComponent { } } -export default connect( - state => ({ - auth: getAuth(state), - }), - boundActions, -)(DevAuthScreen); +export default connectWithActions(state => ({ + auth: getAuth(state), +}))(DevAuthScreen); diff --git a/src/start/OAuthView.js b/src/start/OAuthView.js index 7741d1daadb..a0366ca5c53 100644 --- a/src/start/OAuthView.js +++ b/src/start/OAuthView.js @@ -1,11 +1,10 @@ /* @flow */ import React, { Component } from 'react'; import { Linking } from 'react-native'; -import { connect } from 'react-redux'; import parseURL from 'url-parse'; import type { Actions } from '../types'; -import boundActions from '../boundActions'; +import connectWithActions from '../connectWithActions'; import { ZulipButton } from '../common'; import { getCurrentRealm } from '../selectors'; import { extractApiKey } from '../utils/encoding'; @@ -105,9 +104,6 @@ class OAuthView extends Component { } } -export default connect( - state => ({ - realm: getCurrentRealm(state), - }), - boundActions, -)(OAuthView); +export default connectWithActions(state => ({ + realm: getCurrentRealm(state), +}))(OAuthView); diff --git a/src/start/PasswordAuthView.js b/src/start/PasswordAuthView.js index 2008362d001..ed1180f592e 100644 --- a/src/start/PasswordAuthView.js +++ b/src/start/PasswordAuthView.js @@ -1,10 +1,9 @@ /* @flow */ import React, { PureComponent } from 'react'; import { View, StyleSheet } from 'react-native'; -import { connect } from 'react-redux'; import type { Actions, Auth } from '../types'; -import boundActions from '../boundActions'; +import connectWithActions from '../connectWithActions'; import { fetchApiKey } from '../api'; import { ErrorMsg, ZulipButton, Input, PasswordInput, WebLink } from '../common'; import { getAuth, getOwnEmail } from '../selectors'; @@ -120,10 +119,7 @@ class PasswordAuthView extends PureComponent { } } -export default connect( - state => ({ - auth: getAuth(state), - email: getOwnEmail(state), - }), - boundActions, -)(PasswordAuthView); +export default connectWithActions(state => ({ + auth: getAuth(state), + email: getOwnEmail(state), +}))(PasswordAuthView); diff --git a/src/start/RealmScreen.js b/src/start/RealmScreen.js index b6a4e0bdada..e52c711f3d9 100644 --- a/src/start/RealmScreen.js +++ b/src/start/RealmScreen.js @@ -1,10 +1,9 @@ /* @flow */ import React, { PureComponent } from 'react'; import { ScrollView, View, StyleSheet, Keyboard } from 'react-native'; -import { connect } from 'react-redux'; import type { Actions } from '../types'; -import boundActions from '../boundActions'; +import connectWithActions from '../connectWithActions'; import { Centerer, Label, Screen, ErrorMsg, ZulipButton, Input } from '../common'; import { getServerSettings } from '../api'; import { fixRealmUrl } from '../utils/url'; @@ -103,4 +102,4 @@ class RealmScreen extends PureComponent { } } -export default connect(null, boundActions)(RealmScreen); +export default connectWithActions(null)(RealmScreen); diff --git a/src/streams/SubscriptionsContainer.js b/src/streams/SubscriptionsContainer.js index ac5331ca96e..685b2abab83 100644 --- a/src/streams/SubscriptionsContainer.js +++ b/src/streams/SubscriptionsContainer.js @@ -1,17 +1,12 @@ /* @flow */ -import { connect } from 'react-redux'; - -import boundActions from '../boundActions'; +import connectWithActions from '../connectWithActions'; import type { GlobalState } from '../types'; import { getActiveNarrow, getUnreadByStream } from '../selectors'; import SubscriptionsCard from './SubscriptionsCard'; import { getSubscribedStreams } from '../subscriptions/subscriptionSelectors'; -export default connect( - (state: GlobalState) => ({ - narrow: getActiveNarrow(state), - subscriptions: getSubscribedStreams(state), - unreadByStream: getUnreadByStream(state), - }), - boundActions, -)(SubscriptionsCard); +export default connectWithActions((state: GlobalState) => ({ + narrow: getActiveNarrow(state), + subscriptions: getSubscribedStreams(state), + unreadByStream: getUnreadByStream(state), +}))(SubscriptionsCard); diff --git a/src/subscriptions/SubscriptionsContainer.js b/src/subscriptions/SubscriptionsContainer.js index 651297af5cf..20e29d315e5 100644 --- a/src/subscriptions/SubscriptionsContainer.js +++ b/src/subscriptions/SubscriptionsContainer.js @@ -1,16 +1,11 @@ /* @flow */ -import { connect } from 'react-redux'; - import type { GlobalState } from '../types'; import { getAuth } from '../selectors'; -import boundActions from '../boundActions'; +import connectWithActions from '../connectWithActions'; import SubscriptionsCard from './SubscriptionsCard'; -export default connect( - (state: GlobalState) => ({ - auth: getAuth(state), - streams: state.streams, - subscriptions: state.subscriptions, - }), - boundActions, -)(SubscriptionsCard); +export default connectWithActions((state: GlobalState) => ({ + auth: getAuth(state), + streams: state.streams, + subscriptions: state.subscriptions, +}))(SubscriptionsCard); diff --git a/src/title/Title.js b/src/title/Title.js index bf1915d50da..decb0cf8caa 100644 --- a/src/title/Title.js +++ b/src/title/Title.js @@ -1,7 +1,7 @@ /* @flow */ import React, { PureComponent } from 'react'; -import { connect } from 'react-redux'; +import connectWithActions from '../connectWithActions'; import { isHomeNarrow, isPrivateNarrow, @@ -49,7 +49,7 @@ class Title extends PureComponent { } } -export default connect(state => ({ +export default connectWithActions(state => ({ realm: getCurrentRealm(state), narrow: state.chat.narrow, users: state.users, diff --git a/src/title/TitleGroupContainer.js b/src/title/TitleGroupContainer.js index c22822606df..760b70969c3 100644 --- a/src/title/TitleGroupContainer.js +++ b/src/title/TitleGroupContainer.js @@ -1,13 +1,8 @@ /* @flow */ -import { connect } from 'react-redux'; - -import boundActions from '../boundActions'; +import connectWithActions from '../connectWithActions'; import { getRecipientsInGroupNarrow } from '../selectors'; import TitleGroup from './TitleGroup'; -export default connect( - state => ({ - recipients: getRecipientsInGroupNarrow(state), - }), - boundActions, -)(TitleGroup); +export default connectWithActions(state => ({ + recipients: getRecipientsInGroupNarrow(state), +}))(TitleGroup); diff --git a/src/title/TitlePrivateContainer.js b/src/title/TitlePrivateContainer.js index dcc046d3899..63b67056ff9 100644 --- a/src/title/TitlePrivateContainer.js +++ b/src/title/TitlePrivateContainer.js @@ -1,13 +1,8 @@ /* @flow */ -import { connect } from 'react-redux'; - -import boundActions from '../boundActions'; +import connectWithActions from '../connectWithActions'; import { getUserInPmNarrow } from '../selectors'; import TitlePrivate from './TitlePrivate'; -export default connect( - state => ({ - user: getUserInPmNarrow(state), - }), - boundActions, -)(TitlePrivate); +export default connectWithActions(state => ({ + user: getUserInPmNarrow(state), +}))(TitlePrivate); diff --git a/src/title/TitleSpecialContainer.js b/src/title/TitleSpecialContainer.js index 6e5f59da471..667f4d0c808 100644 --- a/src/title/TitleSpecialContainer.js +++ b/src/title/TitleSpecialContainer.js @@ -1,13 +1,8 @@ /* @flow */ -import { connect } from 'react-redux'; - -import boundActions from '../boundActions'; +import connectWithActions from '../connectWithActions'; import { getActiveNarrow } from '../selectors'; import TitleSpecial from './TitleSpecial'; -export default connect( - state => ({ - narrow: getActiveNarrow(state), - }), - boundActions, -)(TitleSpecial); +export default connectWithActions(state => ({ + narrow: getActiveNarrow(state), +}))(TitleSpecial); diff --git a/src/title/TitleStreamContainer.js b/src/title/TitleStreamContainer.js index bc3dd28fc67..171b23feaff 100644 --- a/src/title/TitleStreamContainer.js +++ b/src/title/TitleStreamContainer.js @@ -1,14 +1,9 @@ /* @flow */ -import { connect } from 'react-redux'; - -import boundActions from '../boundActions'; +import connectWithActions from '../connectWithActions'; import { getActiveNarrow, getStreamInNarrow } from '../selectors'; import TitleStream from './TitleStream'; -export default connect( - state => ({ - narrow: getActiveNarrow(state), - stream: getStreamInNarrow(state), - }), - boundActions, -)(TitleStream); +export default connectWithActions(state => ({ + narrow: getActiveNarrow(state), + stream: getStreamInNarrow(state), +}))(TitleStream); diff --git a/src/types.js b/src/types.js index 2b0af5cacc7..bb5dc713273 100644 --- a/src/types.js +++ b/src/types.js @@ -1,7 +1,5 @@ export type { StyleObj } from 'react-native/Libraries/StyleSheet/StyleSheetTypes'; -export type { Connector } from 'react-redux'; - export type Auth = { realm: string, apiKey: string, diff --git a/src/unread/UnreadStreamsContainer.js b/src/unread/UnreadStreamsContainer.js index 8f6a63c657d..65e28f4f30b 100644 --- a/src/unread/UnreadStreamsContainer.js +++ b/src/unread/UnreadStreamsContainer.js @@ -1,14 +1,9 @@ /* @flow */ -import { connect } from 'react-redux'; - -import boundActions from '../boundActions'; +import connectWithActions from '../connectWithActions'; import { getActiveNarrow, getUnreadStreamsAndTopics } from '../selectors'; import UnreadStreamsCard from './UnreadStreamsCard'; -export default connect( - state => ({ - narrow: getActiveNarrow(state), - unreadStreamsAndTopics: getUnreadStreamsAndTopics(state), - }), - boundActions, -)(UnreadStreamsCard); +export default connectWithActions(state => ({ + narrow: getActiveNarrow(state), + unreadStreamsAndTopics: getUnreadStreamsAndTopics(state), +}))(UnreadStreamsCard); diff --git a/src/users/UsersContainer.js b/src/users/UsersContainer.js index 619f4df7979..22f3863b84d 100644 --- a/src/users/UsersContainer.js +++ b/src/users/UsersContainer.js @@ -1,15 +1,10 @@ /* @flow */ -import { connect } from 'react-redux'; - import { getOwnEmail, getAllActiveUsers, getPresence } from '../selectors'; -import boundActions from '../boundActions'; +import connectWithActions from '../connectWithActions'; import UsersCard from './UsersCard'; -export default connect( - state => ({ - ownEmail: getOwnEmail(state), - users: getAllActiveUsers(state), - presences: getPresence(state), - }), - boundActions, -)(UsersCard); +export default connectWithActions(state => ({ + ownEmail: getOwnEmail(state), + users: getAllActiveUsers(state), + presences: getPresence(state), +}))(UsersCard);