This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const store = createStore( | |
| rootReducer, | |
| compose(applyMiddleware(/** other middlewares */, getWeatherDataMiddleware)) | |
| ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const getWeatherDataTimedout = async dispatch => { | |
| await getWeatherData()(dispatch); | |
| setTimeout(() => updateMessages(dispatch), 30 * 1000); | |
| }; | |
| const getWeatherDataMiddleware = ({ dispatch }) => next => { | |
| getWeatherDataTimedout(dispatch); | |
| return action => next(action); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| export const initActions = async dispatch => { | |
| let updateTimeout; | |
| getWeatherDataTimedout = async () => { | |
| await dispatch(getWeatherData()); | |
| updateTimeout = setTimeout(getWeatherDataTimedout, 30 * 1000); | |
| } | |
| /** Initialize any other actions */ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class WeatherApp extends React.Component { | |
| updateTimeout; | |
| componentDidMount() { | |
| this.getWeatherData(); | |
| } | |
| getWeatherData = async () => { | |
| await this.props.getWeatherData(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class WeatherApp extends Rect.Component { | |
| updateInterval; | |
| componentDidMount() { | |
| this.updateInterval = setInterval(() => { | |
| this.props.getWeatherData(); | |
| }, 1000 * 30); // 30 seconds | |
| } | |
| componentWillUnmount() { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const EnumStatus = { | |
| LOADED: 'LOADED', | |
| LOADING: 'LOADING', | |
| FAILED: 'FAILED' | |
| } | |
| const state = { | |
| subState_1: { | |
| data: any, | |
| status: EnumStatus |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const store = createStore( | |
| rootReducer, | |
| compose(applyMiddleware(/** other middlewares */, updateMessagesMiddleware)) | |
| ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const updateMessagesMiddleware = ({ dispatch }) => next => { | |
| const updateMessages = async () => { | |
| await getNewMessages()(dispatch); | |
| setTimeout(updateMessages, 500); | |
| }; | |
| updateMessages(); | |
| return action => next(action); | |
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| export const initActions = async dispatch => { | |
| let updateTimeout; | |
| updateMessages = async () => { | |
| await dispatch(getNewMessages()); | |
| updateTimeout = setTimeout(updateMessages, 500); | |
| } | |
| updateMessages(); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class NewMessages extends React.PureComponent { | |
| updateTimeout; | |
| componentDidMount() { | |
| this.updateMessages(); | |
| } | |
| updateMessages = async () => { | |
| // thunk | |
| await this.props.getNewMessages(); // waiting for request |
NewerOlder