New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Remove circular dependency from debugging code #1354
Conversation
facdb9c
to
c09c09e
Compare
Review @simov @seanstrom @FredKSchott ? |
Looks good, though are we forced to have the debug module inlined into request.js ? |
I was having trouble thinking of a clean way to pass the needed flag. I guess something like this would work though:
module.exports = function(Request) {
Request.debug = // do process.env check
return function debug(msg) {
if (Request.debug) {
// do stuff
}
}
} and in var debug = require('./lib/debug')(Request) Do you think this is better than just having it inlined? |
Ehm, It's probably better to have it inline. Now that I see the alternative. |
c09c09e
to
b27582a
Compare
Move the `debug` property from `request` to `request.Request`, and define a property at the old location to pass through to the new location for backwards compatibility.
This was probably not a very good idea.
b27582a
to
e7c7784
Compare
@@ -240,6 +239,14 @@ function Request (options) { | |||
|
|||
util.inherits(Request, stream.Stream) | |||
|
|||
// Debugging | |||
Request.debug = process.env.NODE_DEBUG && /\brequest\b/.test(process.env.NODE_DEBUG) | |||
function debug() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: I'd expect to see the debug function up with the other inlined functions, instead of here in the Request prototype methods
+1 lgtm (with 1 small comment) |
Yeah that's one of the reasons I wanted some review on this. It's here because the linter complains about use of |
@FredKSchott I guess I could put |
Ah yea, I see that now. In that case I'm fine with what you have written, it makes sense given the layout. Although it also means our constructor could never call debug, which is a shame. Not sure if defining The only other solution I can think of would be to define some |
Agreed, and I'd rather avoid adding more machinery here. Somebody besides me want to merge this? Minor issues in the scheme of things, but I've been reminded of this article a lot lately: http://stilldrinking.org/programming-sucks |
Haha yea, but I'm glad these are our problems now, vs "what the hell is this code doing please halp" Also fwiw, you can always enable/disable eslint rules within certain code blocks: /*eslint-disable no-alert, no-console */
alert('foo');
console.log('bar');
/*eslint-enable no-alert */ |
Remove circular dependency from debugging code
thanks @seanstrom for the separation of duties :) |
Make debug a prototype method. This has a couple of advantages: - It's no longer necessary for the debug code to be at a specific place in request.js, see request#1354 - It's easier for helper methods in other files to generate debug messages, see request#1360
This circular dependency is giving me problems with browserify, see
browserify/browserify#1068.
Move the
debug
property fromrequest
torequest.Request
, anddefine a property at the old location to pass through to the new
location for backwards compatibility.