All files middleware.ts

41.94% Statements 13/31
16.67% Branches 3/18
50% Functions 4/8
39.29% Lines 11/28

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 551x         1x         1x     1x   1x 1x       1x   1x 1x 1x 1x                                                          
const redux = (reducer: any, initial: any) => (
  set: any,
  get: any,
  api: any
) => {
  api.dispatch = (action: any) => {
    set((state: any) => reducer(state, action))
    api.devtools && api.devtools.send(action, get())
    return action
  }
  return { dispatch: api.dispatch, ...initial }
}
 
const devtools = (fn: any) => (set: any, get: any, api: any) => {
  let extension
  try {
    extension =
      (window as any).__REDUX_DEVTOOLS_EXTENSION__ ||
      (window as any).top.__REDUX_DEVTOOLS_EXTENSION__
  } catch {}
  let ignoreState = false
 
  Eif (!extension) {
    console.warn('Please install/enable Redux devtools extension')
    api.devtools = null
    return fn(set, get, api)
  } else {
    const initialState = fn(set, get, api)
    if (!api.devtools) {
      api.devtools = extension.connect()
      api.devtools.subscribe((message: any) => {
        if (message.type === 'DISPATCH' && message.state) {
          ignoreState =
            message.payload.type === 'JUMP_TO_ACTION' ||
            message.payload.type === 'JUMP_TO_STATE'
          set(JSON.parse(message.state), true)
        }
      })
      api.devtools.init(initialState)
      if (!initialState.dispatch) {
        api.subscribe((state: any) => {
          if (!ignoreState) {
            api.devtools.send('setState', state)
          } else {
            ignoreState = false
          }
        })
      }
    }
    return initialState
  }
}
 
export { devtools, redux }