Skip to content

Commit

Permalink
add a destroy() function to debug instances
Browse files Browse the repository at this point in the history
So that "dynamically created instances" can clean up after themselves
  • Loading branch information
TooTallNate committed Apr 12, 2017
1 parent eb8d451 commit b5f5597
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/debug.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ function createDebug(namespace) {
debug.enabled = exports.enabled(namespace);
debug.useColors = exports.useColors();
debug.color = selectColor(namespace);
debug.destroy = destroy;

// env-specific initialization logic for debug instances
if ('function' === typeof exports.init) {
Expand All @@ -130,6 +131,11 @@ function createDebug(namespace) {
return debug;
}

function destroy () {
const index = exports.instances.indexOf(this)
exports.instances.splice(index, 1)
}

/**
* Enables a debug mode by namespaces. This can include modes
* separated by a colon and wildcards.
Expand Down

0 comments on commit b5f5597

Please sign in to comment.