Skip to content

sidebar()'s input value should encode the open (not closed) state - #603

Merged
cpsievert merged 1 commit into
mainfrom
sidebar-input-val-fix
Jun 2, 2023
Merged

cpsievert merged 1 commit into
mainfrom
sidebar-input-val-fix

Conversation

@cpsievert

Copy link
Copy Markdown
Collaborator

Closes #600

@cpsievert
cpsievert merged commit d31c276 into main Jun 2, 2023
@cpsievert
cpsievert deleted the sidebar-input-val-fix branch June 2, 2023 18:51
Comment on lines +382 to +383
const closed = sb?.isClosed;
return closed === undefined ? false : !closed;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cpsievert Is this a style choice or a technical choice? In other words, is there a reason for this approach rather than fixing the negation, e.g.

    return sb ? !sb.isClosed : false;

If it's stylistic, I'd agree I'm not that into using a ternary here, but I would have preferred

    if (!sb) return false;
    return !sb.isClosed;

@cpsievert cpsievert Jun 6, 2023 •

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IIRC, return sb ? !sb.isClosed : false; doesn't actually return what you'd expect (the !sb.isClosed doesn't negate properly)

If this actually works, I won't be opposed to it:

    if (!sb) return false;
    return !sb.isClosed;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm pretty sure the ternary does what we'd expect; at least it works as expected with the reprex and if I extract the code idea into a JS reprex: https://codepen.io/gadenbuie/pen/dyQyXyP (expand the console to see the log messages).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Input value for sidebar() is opposite what it should be

3 participants