| 3 |
liveuser |
1 |
# Introduction
|
|
|
2 |
|
|
|
3 |
Événement is is French and means "event". The événement library aims to
|
|
|
4 |
provide a simple way of subscribing to events and notifying those subscribers
|
|
|
5 |
whenever an event occurs.
|
|
|
6 |
|
|
|
7 |
The API that it exposes is almost a direct port of the EventEmitter API found
|
|
|
8 |
in node.js. It also includes an "EventEmitter". There are some minor
|
|
|
9 |
differences however.
|
|
|
10 |
|
|
|
11 |
The EventEmitter is an implementation of the publish-subscribe pattern, which
|
|
|
12 |
is a generalized version of the observer pattern. The observer pattern
|
|
|
13 |
specifies an observable subject, which observers can register themselves to.
|
|
|
14 |
Once something interesting happens, the subject notifies its observers.
|
|
|
15 |
|
|
|
16 |
Pub/sub takes the same idea but encapsulates the observation logic inside a
|
|
|
17 |
separate object which manages all of its subscribers or listeners. Subscribers
|
|
|
18 |
are bound to an event name, and will only receive notifications of the events
|
|
|
19 |
they subscribed to.
|
|
|
20 |
|
|
|
21 |
**TLDR: What does evenement do, in short? It provides a mapping from event
|
|
|
22 |
names to a list of listener functions and triggers each listener for a given
|
|
|
23 |
event when it is emitted.**
|
|
|
24 |
|
|
|
25 |
Why do we do this, you ask? To achieve decoupling.
|
|
|
26 |
|
|
|
27 |
It allows you to design a system where the core will emit events, and modules
|
|
|
28 |
are able to subscribe to these events. And respond to them.
|