From 6cfd139cc24a82cf271e133cfcb224e8432b4e6d Mon Sep 17 00:00:00 2001 From: Thibaud Colas Date: Wed, 7 Jun 2017 17:21:00 +0300 Subject: [PATCH] Inline util from redux-actions to reduce bundle size --- .../__snapshots__/actions.test.js.snap | 1 + client/src/components/Explorer/actions.js | 3 +-- client/src/utils/actions.js | 25 +++++++++++++++++++ package.json | 1 - 4 files changed, 27 insertions(+), 3 deletions(-) create mode 100644 client/src/utils/actions.js diff --git a/client/src/components/Explorer/__snapshots__/actions.test.js.snap b/client/src/components/Explorer/__snapshots__/actions.test.js.snap index aef56507c..43442ce5d 100644 --- a/client/src/components/Explorer/__snapshots__/actions.test.js.snap +++ b/client/src/components/Explorer/__snapshots__/actions.test.js.snap @@ -31,6 +31,7 @@ Array [ exports[`actions toggleExplorer close 1`] = ` Array [ Object { + "payload": undefined, "type": "CLOSE_EXPLORER", }, ] diff --git a/client/src/components/Explorer/actions.js b/client/src/components/Explorer/actions.js index 08a635146..002d98f03 100644 --- a/client/src/components/Explorer/actions.js +++ b/client/src/components/Explorer/actions.js @@ -1,6 +1,5 @@ -import { createAction } from 'redux-actions'; - import * as admin from '../../api/admin'; +import { createAction } from '../../utils/actions'; import { MAX_EXPLORER_PAGES } from '../../config/wagtailConfig'; const getPageStart = createAction('GET_PAGE_START'); diff --git a/client/src/utils/actions.js b/client/src/utils/actions.js new file mode 100644 index 000000000..3fbf44d60 --- /dev/null +++ b/client/src/utils/actions.js @@ -0,0 +1,25 @@ +const identity = func => func; + +// Stolen from the following project (had a 18kb footprint at the time). +// https://github.com/acdlite/redux-actions/blob/79c68635fb1524c1b1cf8e2398d4b099b53ca8de/src/createAction.js +export function createAction(type, actionCreator, metaCreator) { + const finalActionCreator = typeof actionCreator === 'function' ? actionCreator : identity; + + return (...args) => { + const action = { + type, + payload: finalActionCreator(...args), + }; + + if (action.payload instanceof Error) { + // Handle FSA errors where the payload is an Error object. Set error. + action.error = true; + } + + if (typeof metaCreator === 'function') { + action.meta = metaCreator(...args); + } + + return action; + }; +} diff --git a/package.json b/package.json index d086683ec..435733b59 100644 --- a/package.json +++ b/package.json @@ -64,7 +64,6 @@ "react-redux": "^5.0.5", "react-transition-group": "^1.1.3", "redux": "^3.6.0", - "redux-actions": "^2.0.3", "redux-thunk": "^2.2.0", "whatwg-fetch": "^2.0.2" },