Omnibus 0.0.6 released: New helper functions to simplify event handling
The new version of Omnibus is out with set of new helper functions. You can now delay, filter, skip duplicates as well as debounce and throttle your events. In this article I will give a quick rundown of how you can use those in practice.
If it’s the first time you hear about omnibus, I recommend reading my other article where I describe it’s main concepts:
Introducing Omnibus: new Event Bus library written in TypeScript
event bus library for all
You can use
delay function to delay an event by certain time. The following code will trigger ping / pong in turns every 500ms (0.5s).
You can filter certain events using
filter helper function:
Optionally you can use second argument passed to filter function that is the value of the previous successful call. The following code will only log powers of 2:
Skip duplicates will skip all duplicated events appearing in a row. It’s good if you want to subscribe only to change of a parameter.
Let’s imagine you want to detect if the mouse moved between 100x100px quadrants on the page. You can achieve it in the following way: