-
Notifications
You must be signed in to change notification settings - Fork 545
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
72 additions
and
7 deletions.
There are no files selected for viewing
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
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
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
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
'use strict' | ||
|
||
module.exports = function compose (...args) { | ||
// So we handle [interceptor1, interceptor2] or interceptor1, interceptor2, ... | ||
const interceptors = Array.isArray(args[0]) ? args[0] : args | ||
|
||
let dispatch | ||
|
||
for (let interceptor of interceptors) { | ||
if (interceptor == null) { | ||
continue | ||
} | ||
|
||
if (typeof interceptor !== 'function') { | ||
if (interceptor?.dispatch === 'function') { | ||
interceptor = interceptor.dispatch.bind(interceptor) | ||
} else { | ||
throw new TypeError(`invalid interceptor, expected function received ${typeof interceptor}`) | ||
} | ||
} | ||
|
||
dispatch = interceptor(dispatch) | ||
|
||
if (dispatch == null || typeof dispatch !== 'function' || dispatch.length !== 2) { | ||
throw new TypeError('invalid interceptor') | ||
} | ||
} | ||
|
||
return dispatch | ||
} |