MCPcopy Create free account
hub / github.com/bigskysoftware/_hyperscript / _subscribeEffect

Method _subscribeEffect

www/js/_hyperscript.esm.js:3348–3392  ·  view source on GitHub ↗

* Subscribe an effect to all its current deps. * Symbols go into per-element/global subscription maps. * Attributes, properties, and queries use flat lookup maps * dispatched by the global observer. * @param {Effect} effect

(effect)

Source from the content-addressed store, hash-verified

3346 * @param {Effect} effect
3347 */
3348 _subscribeEffect(effect) {
3349 var reactivity2 = this;
3350 var needsGlobalObserver = false;
3351 for (var [depKey, dep] of effect.dependencies) {
3352 if (dep.type === "symbol" && dep.scope === "global") {
3353 if (!reactivity2._globalSymbolSubscriptions.has(dep.name)) {
3354 reactivity2._globalSymbolSubscriptions.set(dep.name, /* @__PURE__ */ new Set());
3355 }
3356 reactivity2._globalSymbolSubscriptions.get(dep.name).add(effect);
3357 } else if (dep.type === "symbol" && dep.scope === "element") {
3358 var state = reactivity2._getObjectState(dep.element);
3359 if (!state.subscriptions) {
3360 state.subscriptions = /* @__PURE__ */ new Map();
3361 }
3362 if (!state.subscriptions.has(dep.name)) {
3363 state.subscriptions.set(dep.name, /* @__PURE__ */ new Set());
3364 }
3365 state.subscriptions.get(dep.name).add(effect);
3366 } else if (dep.type === "attribute") {
3367 var attrState = reactivity2._getObjectState(dep.element);
3368 var attrKey = dep.name + ":" + attrState.id;
3369 if (!reactivity2._attributeSubscriptions.has(attrKey)) {
3370 reactivity2._attributeSubscriptions.set(attrKey, /* @__PURE__ */ new Set());
3371 }
3372 reactivity2._attributeSubscriptions.get(attrKey).add(effect);
3373 needsGlobalObserver = true;
3374 } else if (dep.type === "property") {
3375 var propState = reactivity2._getObjectState(dep.object);
3376 if (!reactivity2._propertySubscriptions.has(propState.id)) {
3377 reactivity2._propertySubscriptions.set(propState.id, /* @__PURE__ */ new Set());
3378 }
3379 reactivity2._propertySubscriptions.get(propState.id).add(effect);
3380 needsGlobalObserver = true;
3381 } else if (dep.type === "query") {
3382 if (!reactivity2._querySubscriptions.has(dep.root)) {
3383 reactivity2._querySubscriptions.set(dep.root, /* @__PURE__ */ new Set());
3384 }
3385 reactivity2._querySubscriptions.get(dep.root).add(effect);
3386 needsGlobalObserver = true;
3387 }
3388 }
3389 if (needsGlobalObserver) {
3390 reactivity2._initGlobalObserver();
3391 }
3392 }
3393 /** @param {Effect} effect */
3394 _unsubscribeEffect(effect) {
3395 var reactivity2 = this;

Callers 2

initializeMethod · 0.45
runMethod · 0.45

Calls 4

setMethod · 0.45
getMethod · 0.45
_getObjectStateMethod · 0.45
_initGlobalObserverMethod · 0.45

Tested by

no test coverage detected