Completed
Push — master ( 2040ba...cef9c4 )
by Vitaly
02:22
created

applyMiddleware.js ➔ applyMiddleware   A

Complexity

Conditions 2
Paths 5

Size

Total Lines 20

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
c 1
b 0
f 0
nc 5
dl 0
loc 20
rs 9.4285
nop 6

1 Function

Rating   Name   Duplication   Size   Complexity  
A applyMiddleware.js ➔ ... ➔ ??? 0 1 1
1
export default function applyMiddleware(applyTo, middlewares = [], options = {}, params = {}, resourceId = '', method = '') {
2
3
    middlewares = [].concat(middlewares).filter(func => typeof func === 'function');
4
5
    if (!middlewares.length) {
6
        return applyTo(params);
7
    }
8
9
    return middlewares.reduceRight((prev, middleware, index) => {
10
11
        const next = index === middlewares.length - 1
12
            ? prev.bind(null, params)
13
            : prev.bind(null, options, params, resourceId, method);
14
15
        return index === 0
16
            ? middleware(next)(options, params, resourceId, method)
17
            : middleware(next);
18
    }, applyTo);
19
20
}
21