Repository navigation
fix NaN ticks crashing - #1335
Conversation
mbostock
left a comment
There was a problem hiding this comment.
Nice catch. I’m a little surprised (I had forgotten) that the format functions can return undefined. I wonder if it wouldn’t be better to have them return the empty string so that callers can rely on them always returning a string? It looks like this would be acceptable for our usage and it would obviate a need for a workaround here.
I’m also a little surprised that we format invalid dates as “Invalid Date” when we format NaN as undefined (equivalent to the empty string). Maybe those should be more consistent, too? But that’s a separate issue.
mbostock
left a comment
There was a problem hiding this comment.
I experimented more with changing the format functions to return the empty string instead of undefined for the edge cases, and I changed my mind: I think it’s nice to retain the type safety of undefined in these cases. For example, our default filtering removes null and undefined, but not the empty string.
I incorporated the ?? style suggestion.
* Guard against formatDefault returning undefined (it always returns a string except when the value is NaN) Closes observablehq#1334 related to observablehq#493 * coalesce null to empty string * DRY --------- Co-authored-by: Mike Bostock <mbostock@gmail.com>
Guard against formatDefault returning undefined (it always returns a string except when the value is NaN)
Fixes #1334
related to #493