Created
August 26, 2015 17:48
-
-
Save molexx/2f6b3b7d132b9fbf23cd to your computer and use it in GitHub Desktop.
cls-mongoose index.js addition for Models
This file contains hidden or 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
var wrapLastParamInCLSBind = function(clsns, container, functionName) { | |
shimmer.wrap(container, functionName, function (original) { | |
return function() { | |
var lastArg = arguments[arguments.length - 1]; | |
if (lastArg && ('function' == typeof lastArg)) { | |
var clsBoundLastArg = clsns.bind(lastArg); | |
arguments[arguments.length - 1] = clsBoundLastArg; | |
} | |
return original.apply(this, arguments); | |
}; | |
}); | |
}; | |
wrapLastParamInCLSBind(ns, mongoose.Model, 'find'); | |
wrapLastParamInCLSBind(ns, mongoose.Model, 'update'); | |
wrapLastParamInCLSBind(ns, mongoose.Model, 'distinct'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment