| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Changes the custom inspect example to a more complex object that actually uses the parameters of the custom inspect function. I specifically chose a wrapper of a value called a "Box" that inspects to "Box < inner_inspect_value >". I also want there to be documentation explaining what the code is actually doing. E.g., the padding replacement part is to make the inspected value line up properly when multi-line inputs are given. I also went with having a space between the Box's brackets and the inner value because it matches how objects work, and that should definitely be listed as a convention somewhere in here. Also, the convention to shorten only when depth is less than 0, not e.g. at 0. But I don't know how to write the documentation for that, so I'm leaving that to somebody who reads this message. Partially fixes: nodejs#8442
|
This is a partial fix for #8442. |
Sorry, something went wrong.
| }); | ||
|
|
||
| // Five space padding because that's the size of "Box< ". | ||
| const padding = ' '; |
There was a problem hiding this comment.
This can be better written as ' '.repeat(5)
Sorry, something went wrong.
There was a problem hiding this comment.
Done in the next commit. Thanks for pointing out that exists.
Sorry, something went wrong.
|
CI: https://ci.nodejs.org/job/node-test-pull-request/4367/ LGTM. Thanks for the contribution! |
Sorry, something went wrong.
|
Thanks @Havvy. Do you want to take a stab at documenting the example? |
Sorry, something went wrong.
There was a problem hiding this comment.
This looks pretty good, thank you!
Sorry, something went wrong.
| const obj = { name: 'nate' }; | ||
| obj[util.inspect.custom] = function(depth) { | ||
| return `{${this.name}}`; | ||
| }; |
There was a problem hiding this comment.
I’m not sure, so this is just a suggestion, but maybe leaving the “simpler” example first would be helpful? The Box example is good but maybe a bit overwhelming on the first look?
Sorry, something went wrong.
There was a problem hiding this comment.
If we keep it, then I'd argue that we'd want to also add text saying it's a minimal example.
Sorry, something went wrong.
There was a problem hiding this comment.
Sorry, something went wrong.
|
@fhinkel I don't know how to properly document the example in a way that would help new people learn. |
Sorry, something went wrong.
|
|
||
| util.inspect(obj); | ||
| // "{nate}" | ||
| inspect(depth, options) { |
There was a problem hiding this comment.
@addaleax ... what do you think.. should this be modified to use the new symbol you introduced as an alternative to using inspect directly?
Sorry, something went wrong.
There was a problem hiding this comment.
@jasnell We could do that, but the motivation for introducing the symbol-based alternative were objects that have a regular inspect property which would conflict with what Node expects, and that doesn’t really apply to this use case. And as long as v4.x is supported, just using inspect is probably what I would do here, too. (But yeah, it’s hard to explain that situation concisely in an example).
Sorry, something went wrong.
There was a problem hiding this comment.
LGTM
Sorry, something went wrong.
|
|
||
| util.inspect(obj); | ||
| // "{nate}" | ||
| inspect(depth, options) { |
Sorry, something went wrong.
There was a problem hiding this comment.
Will do when I have time and energy.
Sorry, something went wrong.
| // "{nate}" | ||
| inspect(depth, options) { | ||
| if (depth < 0) { | ||
| return options.stylize('[Box]', 'special'); |
There was a problem hiding this comment.
@Havvy ... likewise here, a comment that describes briefly what options.stylize does.
Sorry, something went wrong.
|
|
||
| // Five space padding because that's the size of "Box< ". | ||
| const padding = ' '.repeat(5); | ||
| const inner = util.inspect(this.value, newOptions).replace(/\n/g, '\n' + padding); |
There was a problem hiding this comment.
And a comment here about what this call to util.inspect is for.
Sorry, something went wrong.
There was a problem hiding this comment.
Will do when I have time and energy.
Sorry, something went wrong.
| // Five space padding because that's the size of "Box< ". | ||
| const padding = ' '.repeat(5); | ||
| const inner = util.inspect(this.value, newOptions).replace(/\n/g, '\n' + padding); | ||
| return options.stylize('Box', 'special') + '< ' + inner + ' >'; |
There was a problem hiding this comment.
I know I already signed off on this but, just as a very minor nit, this could be slightly simplified to:
return `${options.stylize('Box', 'special')}<${inner}>`;
Sorry, something went wrong.
There was a problem hiding this comment.
I am not sure I’d find that more readable… long expressions inside ${} are a bit weird imho.
So, maybe options.stylize('Box', 'special') + < ${inner} >;?
Sorry, something went wrong.
There was a problem hiding this comment.
Do we really want to mix quasiquoting and string concatenation together?
Seems like any option we go with (other than just string concatenation IMO) looks weird.
Sorry, something went wrong.
|
Given that this PR has been open for a while and there are sign-offs on it in its current state, I’m inclined to say “let’s land this and take care of minor adjustments afterwards if still necessary/desired”. |
Sorry, something went wrong.
|
My computer broke, and the one I'm on is too poor to try to do anything, so I haven't been able to anything recently. Sorry. If you want to push this now, it's still better than what we currently have. |
Sorry, something went wrong.
|
@Havvy Sorry to hear that! ☹️ If there are specific changes, you can enable the Allow edits from maintainers checkbox here and ask us to carry them out, but yes, I think this is a big improvement as it is. If nobody objects, I’d like to land this by Thursday. |
Sorry, something went wrong.
Changes the custom inspect example to a more complex object that actually uses the parameters of the custom inspect function. I specifically chose a wrapper of a value called a "Box" that inspects to "Box < inner_inspect_value >". I also want there to be documentation explaining what the code is actually doing. E.g., the padding replacement part is to make the inspected value line up properly when multi-line inputs are given. I also went with having a space between the Box's brackets and the inner value because it matches how objects work, and that should definitely be listed as a convention somewhere in here. Also, the convention to shorten only when depth is less than 0, not e.g. at 0. But I don't know how to write the documentation for that, so I'm leaving that to somebody who reads this message. Ref: #8442 PR-URL: #8875 Reviewed-By: Evan Lucas <evanlucas@me.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net>
Changes the custom inspect example to a more complex object that actually uses the parameters of the custom inspect function. I specifically chose a wrapper of a value called a "Box" that inspects to "Box < inner_inspect_value >". I also want there to be documentation explaining what the code is actually doing. E.g., the padding replacement part is to make the inspected value line up properly when multi-line inputs are given. I also went with having a space between the Box's brackets and the inner value because it matches how objects work, and that should definitely be listed as a convention somewhere in here. Also, the convention to shorten only when depth is less than 0, not e.g. at 0. But I don't know how to write the documentation for that, so I'm leaving that to somebody who reads this message. Ref: #8442 PR-URL: #8875 Reviewed-By: Evan Lucas <evanlucas@me.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net>
Changes the custom inspect example to a more complex object that actually uses the parameters of the custom inspect function. I specifically chose a wrapper of a value called a "Box" that inspects to "Box < inner_inspect_value >". I also want there to be documentation explaining what the code is actually doing. E.g., the padding replacement part is to make the inspected value line up properly when multi-line inputs are given. I also went with having a space between the Box's brackets and the inner value because it matches how objects work, and that should definitely be listed as a convention somewhere in here. Also, the convention to shorten only when depth is less than 0, not e.g. at 0. But I don't know how to write the documentation for that, so I'm leaving that to somebody who reads this message. Ref: #8442 PR-URL: #8875 Reviewed-By: Evan Lucas <evanlucas@me.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net>
Changes the custom inspect example to a more complex object that actually uses the parameters of the custom inspect function. I specifically chose a wrapper of a value called a "Box" that inspects to "Box < inner_inspect_value >". I also want there to be documentation explaining what the code is actually doing. E.g., the padding replacement part is to make the inspected value line up properly when multi-line inputs are given. I also went with having a space between the Box's brackets and the inner value because it matches how objects work, and that should definitely be listed as a convention somewhere in here. Also, the convention to shorten only when depth is less than 0, not e.g. at 0. But I don't know how to write the documentation for that, so I'm leaving that to somebody who reads this message. Ref: #8442 PR-URL: #8875 Reviewed-By: Evan Lucas <evanlucas@me.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net>
| Back | FazBrowse Home | New Git URL |
Checklist
Affected core subsystem(s)
doc
Description of change
Changes the custom inspect example to a more complex object that
actually uses the parameters of the custom inspect function. I
specifically chose a wrapper of a value called a "Box" that inspects
to "Box < inner_inspect_value >".
I also want there to be documentation explaining what the code is
actually doing. E.g., the padding replacement part is to make the
inspected value line up properly when multi-line inputs are given.
I also went with having a space between the Box's brackets and the
inner value because it matches how objects work, and that should
definitely be listed as a convention somewhere in here.
Also, the convention to shorten only when depth is less than 0,
not e.g. at 0.
But I don't know how to write the documentation for that, so I'm
leaving that to somebody who reads this message.