Skip to content

Commit

Permalink
Simplify connect and boundActions (#1289)
Browse files Browse the repository at this point in the history
  • Loading branch information
borisyankov authored Oct 11, 2017
1 parent fa9e183 commit be28d5b
Show file tree
Hide file tree
Showing 61 changed files with 282 additions and 461 deletions.
16 changes: 6 additions & 10 deletions src/account-info/AccountDetailsScreen.js
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -47,11 +46,8 @@ class AccountDetailsScreen extends Component<Props> {
}
}

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);
16 changes: 6 additions & 10 deletions src/account-info/LogoutButton.js
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -52,11 +51,8 @@ class LogoutButton extends PureComponent<Props> {
}
}

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);
16 changes: 6 additions & 10 deletions src/account-info/SwitchAccountButton.js
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -50,11 +49,8 @@ class SwitchAccountButton extends PureComponent<Props> {
}
}

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);
14 changes: 5 additions & 9 deletions src/account/AccountPickScreen.js
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -60,10 +59,7 @@ class AccountPickScreen extends PureComponent<Props> {
}
}

export default connect(
state => ({
auth: getAuth(state),
accounts: state.accounts,
}),
boundActions,
)(AccountPickScreen);
export default connectWithActions(state => ({
auth: getAuth(state),
accounts: state.accounts,
}))(AccountPickScreen);
4 changes: 2 additions & 2 deletions src/autocomplete/PeopleAutocomplete.js
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -51,7 +51,7 @@ class PeopleAutocomplete extends PureComponent<Props> {
}
}

export default connect((state: GlobalState) => ({
export default connectWithActions((state: GlobalState) => ({
ownEmail: getOwnEmail(state),
users: sortAlphabetically(getAllActiveUsers(state)),
}))(PeopleAutocomplete);
4 changes: 2 additions & 2 deletions src/autocomplete/StreamAutocomplete.js
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -48,6 +48,6 @@ class StreamAutocomplete extends PureComponent<Props> {
}
}

export default connect((state: GlobalState) => ({
export default connectWithActions((state: GlobalState) => ({
subscriptions: getSubscribedStreams(state),
}))(StreamAutocomplete);
12 changes: 4 additions & 8 deletions src/boot/AppDataFetcher.js
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -31,9 +30,6 @@ class AppDataFetcher extends PureComponent<Props> {
}
}

export default connect(
state => ({
needsInitialFetch: state.app.needsInitialFetch,
}),
boundActions,
)(AppDataFetcher);
export default connectWithActions(state => ({
needsInitialFetch: state.app.needsInitialFetch,
}))(AppDataFetcher);
16 changes: 6 additions & 10 deletions src/boot/AppEventHandlers.js
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -93,11 +92,8 @@ class AppEventHandlers extends PureComponent<Props> {
}
}

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);
4 changes: 2 additions & 2 deletions src/boot/StylesProvider.js
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -45,6 +45,6 @@ class StyleProvider extends PureComponent<Props> {
}
}

export default connect(state => ({
export default connectWithActions(state => ({
theme: state.settings.theme,
}))(StyleProvider);
4 changes: 2 additions & 2 deletions src/boot/TranslationProvider.js
Original file line number Diff line number Diff line change
@@ -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';

Expand All @@ -26,6 +26,6 @@ class TranslationProvider extends PureComponent<Props> {
}
}

export default connect(state => ({
export default connectWithActions(state => ({
locale: state.settings.locale,
}))(TranslationProvider);
18 changes: 0 additions & 18 deletions src/boundActions.js

This file was deleted.

19 changes: 7 additions & 12 deletions src/chat/ChatContainer.js
Original file line number Diff line number Diff line change
@@ -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);
5 changes: 2 additions & 3 deletions src/chat/GroupDetailsScreen.js
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -69,4 +68,4 @@ class GroupDetailsScreen extends PureComponent<Props> {
}
}

export default connect(null, boundActions)(GroupDetailsScreen);
export default connectWithActions(null)(GroupDetailsScreen);
4 changes: 2 additions & 2 deletions src/chat/MarkUnreadButton.js
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -85,7 +85,7 @@ class MarkUnreadButton extends PureComponent<Props> {
}
}

export default connect(state => ({
export default connectWithActions(state => ({
auth: getAuth(state),
narrow: getActiveNarrow(state),
streams: getStreams(state),
Expand Down
13 changes: 4 additions & 9 deletions src/chat/UnreadNoticeContainer.js
Original file line number Diff line number Diff line change
@@ -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);
4 changes: 2 additions & 2 deletions src/common/Avatar.js
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -59,6 +59,6 @@ class Avatar extends PureComponent<Props> {
}
}

export default connect(state => ({
export default connectWithActions(state => ({
realm: getCurrentRealm(state),
}))(Avatar);
4 changes: 2 additions & 2 deletions src/common/Screen.js
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -64,6 +64,6 @@ class Screen extends PureComponent<Props> {
}
}

export default connect((state, props) => ({
export default connectWithActions((state, props) => ({
safeAreaInsets: state.app.safeAreaInsets,
}))(Screen);
4 changes: 2 additions & 2 deletions src/common/WebLink.js
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -37,6 +37,6 @@ class WebLink extends PureComponent<Props> {
}
}

export default connect(state => ({
export default connectWithActions(state => ({
realm: getCurrentRealm(state),
}))(WebLink);
Loading

0 comments on commit be28d5b

Please sign in to comment.