Closed esad closed 7 years ago
I realized that KeyboardEvent
is quite new and supported only in recent browser versions, so this conversion really may fail. However in this case, there is no possibility of accessing keyCode
in Event
without doing someunsafeCoerce
like in https://github.com/quephird/space-invaders-ps/blob/master/src/Handlers/Keyboard.purs#L73
At runtime, any JavaScript function can trigger DOM events with arbitrary arguments, and that is partly why there is always a possibility an event listener will not receive a KeyboardEvent
.
eventToKeyboardEvent
is the safest way but in most contexts I think unsafeCoerce
is a fine way to go.
Right now, a generic
Event
is passed, which for any kind of meaningful handling (comparing key codes etc.) needs to be converted toKeyboardEvent
usingeventToKeyboardEvent
which wraps it in an F. Is there really a possibility ofeventToKeyboardEvent
failing for a keyboard event?