From bdad6d168f62fbb49e9a8511417430aa90a0fd83 Mon Sep 17 00:00:00 2001 From: Titouan Rigoudy Date: Thu, 14 Apr 2016 18:07:47 +0200 Subject: [PATCH] Start migrating away from SOCKET_SEND_MESSAGE action. --- src/actions/LoginActions.js | 6 +++--- src/components/LoginStatusPane.js | 9 +++++---- src/components/SolsticeApp.js | 2 +- src/containers/App.js | 2 ++ src/containers/Footer.js | 2 +- src/reducers/socket.js | 22 ++++++++++++++++------ 6 files changed, 28 insertions(+), 15 deletions(-) diff --git a/src/actions/LoginActions.js b/src/actions/LoginActions.js index ac082d7..166114d 100644 --- a/src/actions/LoginActions.js +++ b/src/actions/LoginActions.js @@ -1,7 +1,7 @@ -import { LOGIN_GET_STATUS } from "../actions/ActionTypes"; +import { LOGIN_GET_STATUS } from "../constants/ActionTypes"; export default { - requestStatus: () => ({ - type: LOGIN_GET_STATUS, + getStatus: () => ({ + type: LOGIN_GET_STATUS }) }; diff --git a/src/components/LoginStatusPane.js b/src/components/LoginStatusPane.js index 324474e..a748aee 100644 --- a/src/components/LoginStatusPane.js +++ b/src/components/LoginStatusPane.js @@ -1,7 +1,6 @@ import React, { PropTypes } from "react"; import { connect } from "react-redux"; -import ControlRequest from "../utils/ControlRequest"; import propTypeSymbol from "../utils/propTypeSymbol"; import { LOGIN_STATUS_UNKNOWN, @@ -20,9 +19,9 @@ class LoginStatusPane extends React.Component } componentDidMount() { - const { status, socketSend } = this.props; + const { status, loginActions } = this.props; if (status == LOGIN_STATUS_UNKNOWN) { - this.props.socketSend(ControlRequest.loginStatus()); + loginActions.getStatus(); } } @@ -99,7 +98,9 @@ LoginStatusPane.propTypes = { username: PropTypes.string, motd: PropTypes.string, reason: PropTypes.string, - socketSend: PropTypes.func.isRequired + loginActions: PropTypes.shape({ + getStatus: PropTypes.func.isRequired + }).isRequired }; export default LoginStatusPane; diff --git a/src/components/SolsticeApp.js b/src/components/SolsticeApp.js index 304b589..b23378d 100644 --- a/src/components/SolsticeApp.js +++ b/src/components/SolsticeApp.js @@ -26,7 +26,7 @@ const SolsticeApp = (props) => { return (
- +
); } diff --git a/src/containers/App.js b/src/containers/App.js index 7970d1b..d8691d2 100644 --- a/src/containers/App.js +++ b/src/containers/App.js @@ -4,6 +4,7 @@ import React, {PropTypes} from "react"; import { bindActionCreators } from "redux"; import { connect } from "react-redux"; +import LoginActions from "../actions/LoginActions"; import RoomActions from "../actions/RoomActions"; import SocketActions from "../actions/SocketActions"; import SocketHandlerActions from "../actions/SocketHandlerActions"; @@ -23,6 +24,7 @@ const mapStateToProps = ({ socket, login }) => ({ socket, login }); function mapDispatchToProps(dispatch) { return { actions: { + login: bindActionCreators(LoginActions, dispatch), room: bindActionCreators(RoomActions, dispatch), socket: bindActionCreators(SocketActions, dispatch), socketHandlers: bindActionCreators(SocketHandlerActions, dispatch) diff --git a/src/containers/Footer.js b/src/containers/Footer.js index 664d389..89da9fa 100644 --- a/src/containers/Footer.js +++ b/src/containers/Footer.js @@ -8,7 +8,7 @@ const Footer = ({ actions, login, socket }) => { return ( ); }; diff --git a/src/reducers/socket.js b/src/reducers/socket.js index 5184c8f..9ad7148 100644 --- a/src/reducers/socket.js +++ b/src/reducers/socket.js @@ -1,13 +1,23 @@ import * as types from "../constants/ActionTypes"; import { STATE_OPENING, STATE_OPEN, STATE_CLOSING, STATE_CLOSED -} from "../constants/socket.js"; +} from "../constants/socket"; + +import ControlRequest from "../utils/ControlRequest"; const initialState = { state: STATE_CLOSED }; export default (state = initialState, action) => { + const sendRequest = (controlRequest) => { + try { + state.socket.send(JSON.stringify(controlRequest)); + } catch (err) { + console.log(`Socket error: failed to send ${action.payload}`); + } + }; + switch (action.type) { case types.SOCKET_SET_OPENING: { @@ -44,11 +54,11 @@ export default (state = initialState, action) => { return { ...state, state: state.socket.readyState }; case types.SOCKET_SEND_MESSAGE: - try { - state.socket.send(JSON.stringify(action.payload)); - } catch (err) { - console.log(`Socket error: failed to send ${action.payload}`); - } + sendRequest(action.payload); + return state; + + case types.LOGIN_GET_STATUS: + sendRequest(ControlRequest.loginStatus()); return state; default: