src/middleware.js   A
last analyzed

Complexity

Total Complexity 11
Complexity/F 2.75

Size

Lines of Code 32
Function Count 4

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
cc 0
wmc 11
c 3
b 0
f 0
nc 1
mnd 3
bc 5
fnc 4
dl 0
loc 32
rs 10
bpm 1.25
cpm 2.75
noi 2

1 Function

Rating   Name   Duplication   Size   Complexity  
B middleware.js ➔ ??? 0 29 1
1
import { ACTION_PREFIX, ACTION_TYPES, HISTORY_METHODS} from './constants';
2
import { parsePath } from 'history';
3
4
export default ({ history, routeParser }) => ({ dispatch, getState }) => next => action => {
0 ignored issues
show
Unused Code introduced by
The parameter getState is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
Unused Code introduced by
The parameter dispatch is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
5
6
    if (action.type.indexOf(ACTION_PREFIX) === 0 && action.type !== ACTION_TYPES.LOCATION_CHANGED) {
7
8
        if (action.type === ACTION_TYPES.GO_TO_ROUTE) {
9
            action.type = ACTION_TYPES.PUSH;
10
            action.payload = routeParser(action.payload);
11
        }
12
13
        if ([ACTION_TYPES.PUSH, ACTION_TYPES.REPLACE].includes(action.type)) {
14
15
            action.payload = typeof action.payload === 'string' ? parsePath(action.payload) : action.payload;
16
17
            const sameLocation = history.location.pathname === action.payload.pathname
18
                              && history.location.search === action.payload.search
19
                              && history.location.hash === action.payload.hash;
20
21
            action.type = sameLocation ? ACTION_TYPES.REPLACE : action.type;
22
        }
23
24
        if (HISTORY_METHODS[action.type]) {
25
            history[HISTORY_METHODS[action.type]](action.payload);
26
        }
27
28
        return;
29
    }
30
31
    return next(action); // eslint-disable-line consistent-return
32
};