Created | Urls | Favourites | Opened | Upvotes | Comments |
1 | 0 | 113 | 0 | 0 |
While the ES6 Promise allows us to get rid of long and deep lists of callbacks, Promises still fall short then it comes to recurring events like eg. listening for chat messages on a websocket, because a Promise can only be used one time.
The Observer pattern on the other hand allows using the same object to listen for recurring events.
From Wikipedia :
The observer pattern is a software design pattern in which an object, called the subject, maintains a list of its dependents, called observers, and notifies them automatically of any state changes, usually by calling one of their methods.