* Add or update a subscriber with a specified ID. If subscriber doesn't * yet exist, it will be created using the specified factory. The use * of factory is important to reduce bundling costs for context node. * If `func` returns a function, that function is called on cleanup. * * @pa
(id, Ctor, func, deps)
| 405 | * @template DEP |
| 406 | */ |
| 407 | subscribe(id, Ctor, func, deps) { |
| 408 | const subscribers = this.subscribers_ || (this.subscribers_ = new Map()); |
| 409 | let subscriber = subscribers.get(id); |
| 410 | if (!subscriber) { |
| 411 | subscriber = new Ctor( |
| 412 | /** @type {ContextNode<function(...DEP):void>} */ ( |
| 413 | /** @type {?} */ (this) |
| 414 | ), |
| 415 | func, |
| 416 | deps |
| 417 | ); |
| 418 | subscribers.set(id, subscriber); |
| 419 | } |
| 420 | } |
| 421 | |
| 422 | /** |
| 423 | * Removes the subscriber previously set with `subscribe`. |