mercredi 13 novembre 2019

Publish/Subscribe with CustomEvents in JavaScript

I've got the task to talk about event based communicatoin and the publish/subscribe based communication in JavaScript.

After thinking about it I wonder that the CustomEvents in JavaScript actually use the publish/subscribe pattern.

Dispatching a CustomEvent is like publishing new data or triggering the update function in the subscribers and creating an event listener is the same es subscribing to a publisher.

In other words every time a event is thrown every listener's callback is run is just the same as every time a publisher publishes new data, the subscriber's update functions are called.

Is this a correct solution or did I not got the key concepts fo the two patterns?

Aucun commentaire:

Enregistrer un commentaire