Skip to content

Instantly share code, notes, and snippets.

@mori-dev
Created April 14, 2017 10:04
Show Gist options
  • Save mori-dev/5cf41c8ac71b44b078777a9589a6b30c to your computer and use it in GitHub Desktop.
Save mori-dev/5cf41c8ac71b44b078777a9589a6b30c to your computer and use it in GitHub Desktop.
redux アプリで定期実行処理を書くには / ミドルウェア
function businessLogic(store: any): {stopFlag: boolean} {
// なんらかのビジネスロジックを記述
// ミドルウェアでは次のようにステートを取り出せます。
// const stateName = store.getState().stateName;
return { stopFlag: false };
}
export default (store: any) => (next: any) => (action: any) => {
if (action.type === ActionTypes.CHECK_SAMPLE_EXEC) {
if (businessLogic(store).stopFlag) {
next(stop());
}
}
next(action);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment