mroderick / PubSubJS

Dependency free publish/subscribe for JavaScript

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Advantages over built-in window.dispatchEvent and window.dispatchCustomEvent?

acherkashin opened this issue · comments

Did you come to any conclusions on this?
If so, would you share them in a pull request to improve the documentation?

One evident "advantage" of using PubSubJS is reducing cognitive load for apps and websites running Javascript on the front- and back-end. PubSubJS allows one to publish-subscribe in a unified way in both client and Node.JS. The vanilla alternative would be to use window.dispatchEvent with custom events on the client side, and EventEmitter in NodeJS.

Performance is obviously one thing, as you are restricted to between 60 (old IE) and 250 async updates per second with setTimeout. We could easily increase performance with one or two order of magnitude by replacing setTimeout with another macrotask scheduling mechanism(for instance usingpostMessagein the browser and nativenextTick` on Node).

An alternative take is the one taken by Emittery, which has no dependencies, and just relies on Promise for async dispatching. That's quite clever and very performant, but obviously not targetting ES3 😄