Created
April 28, 2017 08:53
-
-
Save hachibeeDI/4d8a769f0dfaa58e39db4e4cee8c07cc to your computer and use it in GitHub Desktop.
debounced-action-call-middleware.js
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
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