If you're looking to implement event handling using RxJS, check out this example on Plunker: https://plnkr.co/edit/4kPM5FX6vX2QGC0xDQQO
The key function here is called _listenToEvent
:
function _listenToEvent(name, debounceTime) {
rxjs.fromEvent(document, name)
.pipe(
rxjs.operators.debounceTime(debounceTime)
)
.subscribe(() => _updateTimestamp())
}
This function allows you to listen to events on the document object. The debounceTime
parameter enables you to delay sending AJAX requests until after a specified time interval, preventing unnecessary requests triggered by rapid mouse movements or keystrokes. Debouncing for the click
event may not be needed since users don't typically click rapidly.
You can easily incorporate this with a user
service that handles AJAX requests as needed. Keep in mind, though, that this solution may not cover all scenarios. If your code prevents event bubbling, RxJS might miss certain events.