Created
April 14, 2017 10:04
-
-
Save mori-dev/5cf41c8ac71b44b078777a9589a6b30c to your computer and use it in GitHub Desktop.
redux アプリで定期実行処理を書くには / ミドルウェア
This file contains 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
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