-
Notifications
You must be signed in to change notification settings - Fork 17
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
Protocol: Add undocumented message types #9
Protocol: Add undocumented message types #9
Conversation
Might still have to update |
Hey, thanks for taking this on! I don't think you need to change anything else (does I think the main thing that jumps out at me is your handling of '|noinit|namerequired|': readonly ['noinit', 'namerequired', Message];
'|noinit|nonexistent|': readonly ['noinit', 'nonexistent', Message];
'|noinit|joinfailed|': readonly ['noinit', 'joinfailed', Message];
'|noinit|rename|': readonly ['noinit', 'rename', string, string]; Where I would have instead expected maybe: '|noinit|': readonly ['noinit', 'namerequired' | 'nonexistent' | 'joinfailed', Message]
| ['noinit', 'rename', string, string]; and similar for
The way I see |
Note: as mentioned, the entire test suite is failing, but at least it still shows the |
Thanks for the review! I should be able to finish everything later today if that doesn’t interfere with the release schedule. |
No worries, I will wait for this to land before releasing. It doesn't look like there were any tier shifts this month anyway :) |
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.
Super close! Thanks for making these changes.
protocol/src/index.ts
Outdated
'|selectorhtml|': readonly ['selectorhtml', SelectorName, HTML]; | ||
'|refresh|': readonly ['refresh']; | ||
'|tempnotify|': readonly [ | ||
'tempnotify', TempNotifyName, Message, ...[] | [Message] | [Message, string] |
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.
What's going on with this type? The ...[]
is kind of confusing to me, as it the array nesting. Can this be simplified?
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.
It's parsed as ...([] | [Message] | [Message, string])
due to operator precedence and tuple spreading, though some style guides enforce the parentheses anyway for clarity. Could do that or manually split it into a 3-array union, your call.
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.
I think the parens will help at the bare minimum.
['tempnotify', TempNotifyName, Message] | ['tempnotify', TempNotifyName, Message, Message] | ['tempnotify', TempNotifyName, Message, Message, string]
seems the most clear (unless I'm mistaking what this type actually is?). ['tempnotify', TempNotifyName, Message, Message?, string?]
seems less precise but possibly how I might type this if I were doing it, as I'm not positive the extra precision really matters. Up to you which route you want to go, but please add parens if you want to keep the current approach :)
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.
The ?
suffix allows for undefined
and/or skipping the tuple element, so that might not be ideal. Probably best to expand it into the type union then.
Will do this for |expire|
as well.
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.
Yeah, it's less accurate, but we're also trying to put super rigorous types on top of something which is basically just raw strings on the PS side, so I'm usually not to bothered about dropping an ?
for convenience because PS is more likely to break things in the protocol than the undefined
is going to cause problems for people :).
Technically its also the case that for like ['expire']
you can still index at 1 and get undefined
, so really the main difference with ?
is that you're basically implying the array should be length 2 with the second element occasionally undefined
, though if I really wanted to be explicit about that I'd probably go Message | undefined
(its also the case that nothing in the protocol can be undefined
because we can't translate undefined
over the wire).
tl;dr pedantically yes, the ?
implies some things different than the union, but in practice I'm not too hot and bothered by it in the context of the PS protocol :)
Thanks! I'll import the latest PS changes and cut a new release. |
Fix #8.