Skip to content

Instantly share code, notes, and snippets.

@hachibeeDI
Created April 28, 2017 08:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hachibeeDI/4d8a769f0dfaa58e39db4e4cee8c07cc to your computer and use it in GitHub Desktop.
Save hachibeeDI/4d8a769f0dfaa58e39db4e4cee8c07cc to your computer and use it in GitHub Desktop.
debounced-action-call-middleware.js
import debounce from 'lodash.debounce';
export default function validationDebounceMiddlewareGenerator ({triggerActionTypes, validatorActionType, wait}) {
const createValidateActionDebounced = debounce(
dispatch => dispatch({type: validatorActionType}),
wait
);
return function validationDebounceMiddleware (store) {
return next => action => {
const result = next(action);
if (triggerActionTypes.includes(action.type) === false) {
return result;
}
createValidateActionDebounced(store.dispatch);
return result;
};
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment