- Notifications
You must be signed in to change notification settings - Fork 159
Add type parameter for MessageEvent#data #687
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
Conversation
| EventSource[JC] def dispatchEvent(evt: Event): Boolean | ||
| EventSource[JC] var onerror: js.Function1[ErrorEvent, _] | ||
| EventSource[JC] var onmessage: js.Function1[MessageEvent, _] | ||
| EventSource[JC] var onmessage: js.Function1[MessageEvent[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.
Educated guess based on:
The server-side script that sends events needs to respond using the MIME type
text/event-stream. Each notification is sent as a block of text terminated by a pair of newlines.
| RTCDataChannel[JT] var onclose: js.Function1[Event, Any] | ||
| RTCDataChannel[JT] var onerror: js.Function1[Event, Any] | ||
| RTCDataChannel[JT] var onmessage: js.Function1[MessageEvent, Any] | ||
| RTCDataChannel[JT] var onmessage: js.Function1[MessageEvent[String | Blob | ArrayBuffer], Any] |
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.
Educated guess based on:
https://developer.mozilla.org/en-US/docs/Web/API/RTCDataChannel/send
| WebSocket[JC] var onclose: js.Function1[CloseEvent, _] | ||
| WebSocket[JC] var onerror: js.Function1[ErrorEvent, _] | ||
| WebSocket[JC] var onmessage: js.Function1[MessageEvent, _] | ||
| WebSocket[JC] var onmessage: js.Function1[MessageEvent[String | Blob | ArrayBuffer], _] |
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.
Educated guess based on:
https://developer.mozilla.org/en-US/docs/Web/API/WebSocket/send
| val socket = new dom.WebSocket(echo) | ||
| socket.onmessage = { | ||
| (e: dom.MessageEvent) => | ||
| (e: dom.MessageEvent[_]) => |
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 cheated here, because writing out the union is kind of annoying ...
| Hey @armanbilge. I've read through the patch and I think there's an oversight here. This PR basically does two things, right?
Except if you look at both If we do that, this PR would just be adding a type to WDYT? |
| Woooops 😅 I forgot to add the type parameter to Does that affect your thinking on this? |
| MessageEvent[JC] def cancelable: Boolean | ||
| MessageEvent[JC] def currentTarget: EventTarget | ||
| MessageEvent[JC] def data: Any | ||
| MessageEvent[JC] def data: T |
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.
There we go 😅
| Ah ok that makes sense. Hmmm, well the |
| Hmm, why can't you pattern match? That's how I'm using it currently, and it would be nice to make the "unhandled" default case go away. Although, I'm not sure if Anyway, I was already lukewarm about it so if you're 👎 then yeah, let's just forget it :) |
| Ah, you literally are handling externally and arbitrarily created WS messages 😂😂 In Scala 2 the patmat doesn't understand that there would be one case left unhanded. In fact, a vague part of my memory is telling me you'd need to change
Yeah I'm really on the fence. I love more precision in types! What about if we looked at other usage and tightened the types there? I saw one |
Yup, I think I've done that before. So probably this change won't really help me anyway 🙃
I combed through the spec while working on this and I'm pretty sure that we can't make it any more precise 😕 Going over some of the
I'm no expert on the spec, but overall this seems like a lost cause. |
Hmmm, yeah ok, agree. But thanks for looking into it! It didn't work out but it was a worthy goal to try 😊 |
So, I was motivated to do this because the lack of precision annoyed me when using the
WebSocketAPIs. But for the record I'm not totally convinced if it's a good trade-off in terms of usability vs correctness.Anyis really as precise as you can be, anyway.MessageEvent#data. I did populate it where I could, based on my inference/understanding. But I could be totally wrong there 😆