Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow for auth plugin to be a class or non-class function, and resolve
issue with ws library retiring upgradeReq property
- Loading branch information
1 parent
dc31fab
commit 5c3ac52
Showing
4 changed files
with
62 additions
and
11 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
|
||
/** | ||
* A decorator that will wrap a function or a class. In the case of a non-class | ||
* function, the wrapped function will behave exactly the same as before. | ||
* In the case of a class, the wrapper will allow instantiating the function] | ||
* without using the |new| keyword. This is useful when you don't know | ||
* ahead of time if the function you will be calling is a class or a non-class | ||
* function | ||
* | ||
* @param {function} function_or_class | ||
*/ | ||
exports.factorify = function factorify(function_or_class) { | ||
return (...args) => { | ||
try { | ||
return function_or_class(...args); | ||
} catch (e) { | ||
if (e instanceof TypeError) { | ||
return new function_or_class(...args); | ||
} else { | ||
throw e; | ||
} | ||
} | ||
} | ||
} |
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