MCPcopy Create free account
hub / github.com/ampproject/amphtml / subscribe

Method subscribe

src/core/context/node.js:407–420  ·  view source on GitHub ↗

* 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)

Source from the content-addressed store, hash-verified

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`.

Callers

nothing calls this directly

Calls 2

getMethod · 0.45
setMethod · 0.45

Tested by

no test coverage detected