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

Method _subscribeEffect

www/js/_hyperscript.js:3350–3394  ·  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

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