January 2019
Beginner
210 pages
4h 47m
English
In an implementation of the observer pattern, we can have many known listener entities that subscribe to messages. The following code snippet contains a very basic implementation of a listener in the observer pattern:
class Listener<T> { public update: (message: T) => void; public constructor(fn: (message: T) => void) { this.update = fn; }}
A Listener has a method named update, which is invoked when a second entity known as the Producer generates a new message. A Producer instance manages a number of Listener instances. A message can be generated with the notify method. The message is then passed to all the subscribed listeners. The following code snippet contains a very basic implementation of a producer in the observer ...
Read now
Unlock full access