MCPcopy Index your code
hub / github.com/ampproject/amphtml / subscribe

Method subscribe

src/core/context/values.js:187–200  ·  view source on GitHub ↗

* Adds a subscriber for the specified property. If the property has not * yet been tracked, the tracking is started. If the used value is * already available, the handler is called immediately. The handler is * only called if a valid used value is available and only if this value * has c

(prop, handler)

Source from the content-addressed store, hash-verified

185 * @template T
186 */
187 subscribe(prop, handler) {
188 const used = this.startUsed_(prop);
189
190 if (!pushIfNotExist(used.subscribers, handler)) {
191 // Already a subscriber.
192 return;
193 }
194
195 // The handler is notified right away if the value is available.
196 const existingValue = used.value;
197 if (isDefined(existingValue) && this.isConnected_()) {
198 handler(existingValue);
199 }
200 }
201
202 /**
203 * Unsubscribes a previously added handler. If there are no other subscribers

Callers 5

startUsed_Method · 0.95
facebookFunction · 0.45
subscribeFunction · 0.45
constructorMethod · 0.45

Calls 5

startUsed_Method · 0.95
isConnected_Method · 0.95
pushIfNotExistFunction · 0.90
isDefinedFunction · 0.70
handlerFunction · 0.50

Tested by

no test coverage detected