web
This package exposes a set of handy bindings to browser APIs.
Installation
onEvent
The onEvent
function enables you to respond to various types of events for the target element that supports the addEventListener
interface, such as HTMLInputElement
or WebSocket
, among others.
You can pass a callback as the last argument. In this case, the method will return an unsubscribe function. If you skip the callback, the returned value will be a promise that will resolve with the event.
Please note that this API handles the abort context from the onConnect effect and other Reatom APIs. It enables you to describe complex logic in a concise and clear manner with memory safety underneath.
onEvent WebSocket example
Here is a usage example, which was revrited from this observable example: