Skip to content

Commit

Permalink
issue 5: resolved
Browse files Browse the repository at this point in the history
  • Loading branch information
nmccready committed Mar 28, 2018
1 parent 0144db9 commit 821b8f8
Show file tree
Hide file tree
Showing 5 changed files with 123 additions and 116 deletions.
1 change: 1 addition & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
tag-version-prefix=""
package-lock=false
24 changes: 10 additions & 14 deletions src/lazy-eval.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,28 +16,24 @@ function _resolveOutput(func, bindThis) {
objectAssign(wrapped, func);

return wrapped;
};

}

function wrapEval(_debug) {

var debugOrig = _debug;
var noop = function(){};

function debug(namespace) {

function noop() {}
var instance = debugOrig(namespace);

// if we're not enabled then don't attempt to log anything
// if a debug namespace wraps its debug in a closure then it never allocates anything but the function itself
if (!instance.enabled){
/*
If we're not enabled then don't attempt to log anything.
Therefore when a debug namespace wraps its debug in a
closure then it never allocates anything but the function itself
*/
if (!instance.enabled) {
objectAssign(noop, instance);
instance = noop;
}
else {
instance = _resolveOutput(instance);
return noop;
}
return instance;
return _resolveOutput(instance);
}

var debugMemoized = memoize(debug);
Expand Down
18 changes: 8 additions & 10 deletions src/spawn.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
function spawnFactory(_namespace, _debugFabFactory) {
var memoize = require('memoizee');
var namespace = _namespace || '';
var debugFabFactory = _debugFabFactory;

if(!debugFabFactory){
debugFabFactory = require('./debugFabFactory')();
}

function spawn(ns) {
// this is this.debug (from Debugger)
var dbg = new Debugger(this.namespace, ns);

return dbg.debug;
};

function Debugger(_base, _ns){
var base = _base || '';
var ns = _ns || '';
Expand All @@ -15,17 +21,9 @@ function spawnFactory(_namespace, _debugFabFactory) {
var debug = debugFabFactory(newNs);

this.debug = debug;
this.debug.spawn = this.spawn;
this.debug.spawn = spawn;
}

Debugger.prototype.spawn = function(ns) {
var dbg = new Debugger(this.namespace, ns);

return dbg.debug;
};

Debugger.prototype.spawn = memoize(Debugger.prototype.spawn);

var rootDebug = (new Debugger(namespace)).debug;

return rootDebug;
Expand Down
File renamed without changes.
Loading

0 comments on commit 821b8f8

Please sign in to comment.