12345678910111213141516171819202122232425262728293031323334353637383940 |
- "use strict";
- Object.defineProperty(exports, "__esModule", {
- value: true
- });
- exports.default = void 0;
- /** A function that accepts a potential "extra argument" value to be injected later,
- * and returns an instance of the thunk middleware that uses that value
- */
- function createThunkMiddleware(extraArgument) {
- // Standard Redux middleware definition pattern:
- // See: https://redux.js.org/tutorials/fundamentals/part-4-store#writing-custom-middleware
- var middleware = function middleware(_ref) {
- var dispatch = _ref.dispatch,
- getState = _ref.getState;
- return function (next) {
- return function (action) {
- // The thunk middleware looks for any functions that were passed to `store.dispatch`.
- // If this "action" is really a function, call it and return the result.
- if (typeof action === 'function') {
- // Inject the store's `dispatch` and `getState` methods, as well as any "extra arg"
- return action(dispatch, getState, extraArgument);
- } // Otherwise, pass the action down the middleware chain as usual
- return next(action);
- };
- };
- };
- return middleware;
- }
- var thunk = createThunkMiddleware(); // Attach the factory function so users can create a customized version
- // with whatever "extra arg" they want to inject into their thunks
- thunk.withExtraArgument = createThunkMiddleware;
- var _default = thunk;
- exports.default = _default;
|