• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1'use strict'
2
3const RedirectHandler = require('../handler/RedirectHandler')
4
5function createRedirectInterceptor ({ maxRedirections: defaultMaxRedirections }) {
6  return (dispatch) => {
7    return function Intercept (opts, handler) {
8      const { maxRedirections = defaultMaxRedirections } = opts
9
10      if (!maxRedirections) {
11        return dispatch(opts, handler)
12      }
13
14      const redirectHandler = new RedirectHandler(dispatch, maxRedirections, opts, handler)
15      opts = { ...opts, maxRedirections: 0 } // Stop sub dispatcher from also redirecting.
16      return dispatch(opts, redirectHandler)
17    }
18  }
19}
20
21module.exports = createRedirectInterceptor
22