Dependency API reference for Dependency in Semantic UI's reactivity system link API Reference
Categories

Dependency

Track reactions by hand. A Dependency records which reactions are listening and re-fires them when you say so. Signals own one internally, which is how signal.depend(), signal.notify(), and signal.hasDependents() work.

Most code never touches Dependency directly. Reach for it when you own a non-signal data source (a store, a cache, an external event) and want reactions to subscribe to it.

Creating

Dependency

new Dependency(...metadata);

Creates a dependency tracker with an empty set of subscribers.

Parameters

NameTypeDescription
metadataanyOptional debugging context, attached only while tracing is on

Usage

import { Dependency } from '@semantic-ui/reactivity';
const dep = new Dependency();

Subscribing

depend

dependency.depend();

Records the currently running reaction as a subscriber. A no-op outside a reaction, so it is safe to call anywhere.

Usage

import { Dependency, reaction } from '@semantic-ui/reactivity';
const dep = new Dependency();
reaction(() => {
dep.depend();
// re-runs whenever dep.changed() fires
});

subscribers

dependency.subscribers;

The live Set of reactions currently subscribed. Read it to introspect, do not mutate it directly. Use remove to drop a subscriber.

Returns

A Set of subscribed reactions. Empty when nothing is listening.

Notifying

changed

dependency.changed(context);

Invalidates every subscribed reaction, scheduling them to re-run. Skips its bookkeeping entirely when nothing is listening.

Parameters

NameTypeDescription
contextobjectOptional metadata about the change, forwarded to invalidated reactions while tracing is on

Usage

import { Dependency, reaction } from '@semantic-ui/reactivity';
const dep = new Dependency();
reaction(() => {
dep.depend();
console.log('ran');
});
dep.changed(); // logs 'ran' again

Removing

remove

dependency.remove(reaction);

Drops a single reaction from the subscriber set. The reaction stops re-running on future changed calls. Reactions are removed automatically when they stop, so you only need this for manual lifecycle control.

Parameters

NameTypeDescription
reactionReactionThe reaction to drop from the subscriber set

Usage

import { Dependency, reaction } from '@semantic-ui/reactivity';
const dep = new Dependency();
const watcher = reaction(() => {
dep.depend();
});
dep.remove(watcher); // watcher no longer fires on dep.changed()
Previous
Scheduler
Next
Number Helpers