links
links copied to clipboard
Event handlers depend on a deprecated feature
The implementation of event handlers in Links depends on the deprecated property window.event (c.f. https://developer.mozilla.org/en-US/docs/Web/API/Window/event). Links exposes this property via a built-in global variable called event.
Ideally, we do not depend on deprecated stuff. However, we need to be careful if we remove event (which by the way is exposed as an uninvocable function*) as we need some other means for retrieving the event context.
I see two approaches:
- Require all user-defined event handlers to accept the current event as a parameter. This would enforce a strong restriction on the type of things one can put inside
l:. - Have the Links Javascript runtime record and store the current event (similarly to how it is done now). Change
event : EventtogetCurrentEvent : () ~> Option(Event), which returnsNoneif it is invoked outside of an event handling context orSome(ev)if inside an event handling context, whereevwould then be bound to the current event. If done naively (as it is currently the case) then different event handlers can read different events depending on when they invokedgetCurrentEvent, we can probably rectify this by making the JavaScript process scheduler take care of the event bookkeeping.
* In the REPL
links> event;
fun : Event
links> event();
<stdin>:1: Type error: The function
`event'
has type
`Event'
while the arguments passed to it have types
and the currently allowed effects are
`wild:()'
In expression: event().