kareem 2.0.3 → 2.0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/index.js +11 -0
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -302,8 +302,19 @@ Kareem.prototype.wrap = function(name, fn, context, args, options) {
302
302
  });
303
303
  };
304
304
 
305
+ Kareem.prototype.hasHooks = function(name) {
306
+ return this._pres[name] != null || this._posts[name] != null;
307
+ };
308
+
305
309
  Kareem.prototype.createWrapper = function(name, fn, context, options) {
306
310
  var _this = this;
311
+ if (!this.hasHooks(name)) {
312
+ // Fast path: if there's no hooks for this function, just return the
313
+ // function wrapped in a nextTick()
314
+ return function() {
315
+ process.nextTick(() => fn.apply(this, arguments));
316
+ };
317
+ }
307
318
  return function() {
308
319
  var _context = context || this;
309
320
  var args = Array.prototype.slice.call(arguments);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "kareem",
3
- "version": "2.0.3",
3
+ "version": "2.0.7",
4
4
  "description": "Next-generation take on pre/post function hooks",
5
5
  "main": "index.js",
6
6
  "scripts": {