{"action":"created","issue":{"url":"https://api.github.com/repos/visionmedia/debug/issues/156","labels_url":"https://api.github.com/repos/visionmedia/debug/issues/156/labels{/name}","comments_url":"https://api.github.com/repos/visionmedia/debug/issues/156/comments","events_url":"https://api.github.com/repos/visionmedia/debug/issues/156/events","html_url":"https://github.com/visionmedia/debug/pull/156","id":48585531,"number":156,"title":"Introducing \"dynamic mode\" allowing enable/disable on the fly","user":{"login":"dominicbarnes","id":160197,"avatar_url":"https://avatars.githubusercontent.com/u/160197?v=3","gravatar_id":"","url":"https://api.github.com/users/dominicbarnes","html_url":"https://github.com/dominicbarnes","followers_url":"https://api.github.com/users/dominicbarnes/followers","following_url":"https://api.github.com/users/dominicbarnes/following{/other_user}","gists_url":"https://api.github.com/users/dominicbarnes/gists{/gist_id}","starred_url":"https://api.github.com/users/dominicbarnes/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dominicbarnes/subscriptions","organizations_url":"https://api.github.com/users/dominicbarnes/orgs","repos_url":"https://api.github.com/users/dominicbarnes/repos","events_url":"https://api.github.com/users/dominicbarnes/events{/privacy}","received_events_url":"https://api.github.com/users/dominicbarnes/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":4,"created_at":"2014-11-13T01:09:42Z","updated_at":"2015-02-18T09:34:54Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/visionmedia/debug/pulls/156","html_url":"https://github.com/visionmedia/debug/pull/156","diff_url":"https://github.com/visionmedia/debug/pull/156.diff","patch_url":"https://github.com/visionmedia/debug/pull/156.patch"},"body":"So, apologies in advance for the extra large PR. This is a feature I think that would be really useful, and I intend to solve several issues in one fell swoop. I'm also wide open to feedback on this, just let me know what you think!\r\n\r\nCurrently, the list of enabled/disabled namespaces is determined during init. Changing the list via `.enable()` and `.disable()` have no effect once a function has already been returned by `debug()`. (#150) This decision allows some optimization at a low-level, which is a good thing. (and why the feature I have here is opt-in)\r\n\r\nFor servers, it could be useful to turn on and off debugging for various features at will, without needing to restart the server to do so. This is what I had in mind while developing this feature, so you'll find a new example demonstrating the use-case. As an aside, I did not implement this feature for browsers yet, since it seems more like a server feature, but it would not be terribly complex to make them more consistent.\r\n\r\nIn dynamic mode, rather than returning a working `enabled` or `disabled` function, it returns a thin wrapper that checks `.enabled(namespace)` when invoked. This allows dynamically turning on and off various debug instances at will.\r\n\r\nTo enable dynamic mode, you can either use `DEBUG_DYN=1` or `debug.dynamic(true);`, but the former is arguably easier. (since it will ensure all debug instances are created in dynamic mode)\r\n\r\nTo facilitate a dynamically-changing list of enabled/disabled namespaces, I needed to overhaul the underlying system. I've created `able.js`, (haha, terrible name, I'm open to alternatives!) along with a mocha test suite. (gives us a good start toward #104) It's a singleton lib that is a simple handler for things like `.enable()`, `.disable()`, `.enabled()` and a bit more. In addition, it includes a `.stringify()` method that generates a list like described in #19. (and a corresponding `.parse()` method for parsing user input)\r\n\r\nAll the fanfare around a distinct \"dynamic mode\" adds some complexity to the code, but this allows the already-optimized version to remain. If you guys are open to it, I'd like to investigate making this the default behavior, and probably benchmarking to see if there's a noticeable difference in performance.\r\n\r\nI tried to be very careful with my changes here, although it was unfortunately difficult without any tests in place. I've tried out all the examples, and they appear to function as designed. Not only that, but I made a special effort to not change the current public API. I also tried to follow the existing code conventions, correct me where I've deviated.\r\n\r\n## tl;dr\r\n\r\n * \"dynamic mode\" allows changing enabled/disabled debugs on the fly (enabled via `DEBUG_DYN=1` or `debug.dynamic(true)`\r\n * `able.js` is the file now responsible for managing the list of enabled/disabled namespaces (it also has tests)\r\n * currently this is opt-in, but I would like to hear thoughts on making it the default behavior\r\n * was careful not to change the public API, and examples were tested thoroughly to make sure it still works (but without proper tests, that was harder than it needed to be)"},"comment":{"url":"https://api.github.com/repos/visionmedia/debug/issues/comments/74836194","html_url":"https://github.com/visionmedia/debug/pull/156#issuecomment-74836194","issue_url":"https://api.github.com/repos/visionmedia/debug/issues/156","id":74836194,"user":{"login":"bydga","id":2520017,"avatar_url":"https://avatars.githubusercontent.com/u/2520017?v=3","gravatar_id":"","url":"https://api.github.com/users/bydga","html_url":"https://github.com/bydga","followers_url":"https://api.github.com/users/bydga/followers","following_url":"https://api.github.com/users/bydga/following{/other_user}","gists_url":"https://api.github.com/users/bydga/gists{/gist_id}","starred_url":"https://api.github.com/users/bydga/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bydga/subscriptions","organizations_url":"https://api.github.com/users/bydga/orgs","repos_url":"https://api.github.com/users/bydga/repos","events_url":"https://api.github.com/users/bydga/events{/privacy}","received_events_url":"https://api.github.com/users/bydga/received_events","type":"User","site_admin":false},"created_at":"2015-02-18T09:34:54Z","updated_at":"2015-02-18T09:34:54Z","body":"Im absolutely +1 for this PR. We are currently using it in our forked private npm module (wit hthis merged), but switching back to the \"official\" module would be nice :)"}}