* Registers a listener to be called on every update this object notifies about. Returns a function * that removes the listener again — call it to stop listening. The base class never drops a listener * on its own, though some subclasses clear all of theirs in `destroy()`. * @param listener
(listener: TListener)
| 25 | * ``` |
| 26 | */ |
| 27 | subscribe(listener: TListener): () => void { |
| 28 | this.listeners.add(listener) |
| 29 | |
| 30 | this.onSubscribe() |
| 31 | |
| 32 | return () => { |
| 33 | this.listeners.delete(listener) |
| 34 | this.onUnsubscribe() |
| 35 | } |
| 36 | } |
| 37 | |
| 38 | /** |
| 39 | * Returns `true` while at least one listener is registered, `false` once they have all unsubscribed. |