From 2b33066ebf7b0645b1b24e3cb2092f63721fd2ac Mon Sep 17 00:00:00 2001 From: Ben Wheeler <wheeler.benjamin@gmail.com> Date: Thu, 15 Nov 2018 16:20:30 -0500 Subject: [PATCH] moved away from using thunk for async --- package.json | 1 - src/lib/alerts/index.jsx | 8 ++++---- src/lib/app-state-hoc.jsx | 12 +++--------- src/lib/project-saver-hoc.jsx | 8 ++++---- src/reducers/alerts.js | 10 +++++----- 5 files changed, 16 insertions(+), 23 deletions(-) diff --git a/package.json b/package.json index 5334feda6..aa891d5be 100644 --- a/package.json +++ b/package.json @@ -97,7 +97,6 @@ "react-tooltip": "3.8.0", "react-virtualized": "9.20.1", "redux": "3.7.2", - "redux-thunk": "2.0.1", "redux-mock-store": "^1.2.3", "redux-throttle": "0.1.1", "rimraf": "^2.6.1", diff --git a/src/lib/alerts/index.jsx b/src/lib/alerts/index.jsx index aec4134f2..9fb1800f8 100644 --- a/src/lib/alerts/index.jsx +++ b/src/lib/alerts/index.jsx @@ -20,7 +20,7 @@ const alerts = [ { alertId: 'createSuccess', alertType: AlertTypes.STANDARD, - clearList: ['createSuccess, creating, saveSuccess, saving'], + clearList: ['createSuccess', 'creating', 'saveSuccess', 'saving'], content: ( <FormattedMessage defaultMessage="Successfully created." @@ -35,7 +35,7 @@ const alerts = [ { alertId: 'creating', alertType: AlertTypes.STANDARD, - clearList: ['createSuccess, creating, saveSuccess, saving'], + clearList: ['createSuccess', 'creating', 'saveSuccess', 'saving'], content: ( <FormattedMessage defaultMessage="Creating..." @@ -71,7 +71,7 @@ const alerts = [ { alertId: 'saveSuccess', alertType: AlertTypes.INLINE, - clearList: ['createSuccess, creating, saveSuccess, saving'], + clearList: ['createSuccess', 'creating', 'saveSuccess', 'saving'], content: ( <FormattedMessage defaultMessage="Successfully saved." @@ -86,7 +86,7 @@ const alerts = [ { alertId: 'saving', alertType: AlertTypes.INLINE, - clearList: ['createSuccess, creating, saveSuccess, saving'], + clearList: ['createSuccess', 'creating', 'saveSuccess', 'saving'], content: ( <FormattedMessage defaultMessage="Saving..." diff --git a/src/lib/app-state-hoc.jsx b/src/lib/app-state-hoc.jsx index 4439d277b..9177c5219 100644 --- a/src/lib/app-state-hoc.jsx +++ b/src/lib/app-state-hoc.jsx @@ -1,8 +1,7 @@ import React from 'react'; import PropTypes from 'prop-types'; import {Provider} from 'react-redux'; -import {applyMiddleware, createStore, combineReducers, compose} from 'redux'; -import thunk from 'redux-thunk'; +import {createStore, combineReducers, compose} from 'redux'; import ConnectedIntlProvider from './connected-intl-provider.jsx'; import localesReducer, {initLocale, localesInitialState} from '../reducers/locales'; @@ -46,9 +45,7 @@ const AppStateHOC = function (WrappedComponent, localesOnly) { // browser modal reducers = {locales: localesReducer}; initialState = {locales: initializedLocales}; - enhancer = composeEnhancers( - applyMiddleware(thunk) - ); + enhancer = composeEnhancers(); } else { // You are right, this is gross. But it's necessary to avoid // importing unneeded code that will crash unsupported browsers. @@ -88,10 +85,7 @@ const AppStateHOC = function (WrappedComponent, localesOnly) { locales: initializedLocales, scratchGui: initializedGui }; - enhancer = composeEnhancers( - guiMiddleware, - applyMiddleware(thunk) - ); + enhancer = composeEnhancers(guiMiddleware); } const reducer = combineReducers(reducers); this.store = createStore( diff --git a/src/lib/project-saver-hoc.jsx b/src/lib/project-saver-hoc.jsx index 9389d3c6d..71787d661 100644 --- a/src/lib/project-saver-hoc.jsx +++ b/src/lib/project-saver-hoc.jsx @@ -259,10 +259,10 @@ const ProjectSaverHOC = function (WrappedComponent) { onManualUpdateProject: () => dispatch(manualUpdateProject()), onProjectError: error => dispatch(projectError(error)), onShowAlert: alertType => dispatch(showStandardAlert(alertType)), - onShowCreateSuccessAlert: () => dispatch(showAlertWithTimeout('createSuccess')), - onShowCreatingAlert: () => dispatch(showAlertWithTimeout('creating')), - onShowSaveSuccessAlert: () => dispatch(showAlertWithTimeout('saveSuccess')), - onShowSavingAlert: () => dispatch(showAlertWithTimeout('saving')), + onShowCreateSuccessAlert: () => showAlertWithTimeout(dispatch, 'createSuccess'), + onShowCreatingAlert: () => showAlertWithTimeout(dispatch, 'creating'), + onShowSaveSuccessAlert: () => showAlertWithTimeout(dispatch, 'saveSuccess'), + onShowSavingAlert: () => showAlertWithTimeout(dispatch, 'saving'), onUpdatedProject: (projectId, loadingState) => dispatch(doneUpdatingProject(projectId, loadingState)) }); // Allow incoming props to override redux-provided props. Used to mock in tests. diff --git a/src/reducers/alerts.js b/src/reducers/alerts.js index 793c47d39..75687d0ee 100644 --- a/src/reducers/alerts.js +++ b/src/reducers/alerts.js @@ -34,7 +34,7 @@ const reducer = function (state, action) { const alertData = alertsData.find(thisAlertData => thisAlertData.alertId === alertId); if (alertData) { const newList = state.alertsList.filter(curAlert => ( - !alertData.clearList || alertData.clearList.indexOf(curAlert.alertId) + !alertData.clearList || alertData.clearList.indexOf(curAlert.alertId) === -1 )); if (action.data && action.data.message) { newAlert.message = action.data.message; @@ -160,10 +160,10 @@ const showExtensionAlert = function (data) { * Function to dispatch showing an alert, with optional * timeout to make it close/go away. * - * @param {object} alertId - the ID of the alert - * @return {null} - do not return a value + * @param {object} dispatch - dispatch function + * @param {string} alertId - the ID of the alert */ -const showAlertWithTimeout = alertId => (dispatch => { +const showAlertWithTimeout = function (dispatch, alertId) { const alertData = alertsData.find(thisAlertData => thisAlertData.alertId === alertId); if (alertData) { dispatch(showStandardAlert(alertId)); @@ -173,7 +173,7 @@ const showAlertWithTimeout = alertId => (dispatch => { }, alertData.maxDisplaySecs * 1000); } } -}); +}; export { reducer as default, -- GitLab