![Logo](/_astro/logo.DNC1PCTe_Z1abT04.webp)
Enter a search term above to see results...
Enter a search term above to see results...
Dependency
is a core class in Semantic UI’s reactivity system that manages dependencies between reactive computations and data sources.
Advanced Use Only - Dependency should not be used by most developers directly to control dependencies, but is instead used internally by
Signal
andReaction
to establish reactivity. Only some particular advanced use cases or metaframeworks will need to access this class directly.
Creates a new Dependency instance.
new Dependency()
import { Dependency } from '@semantic-ui/reactivity';
const dep = new Dependency();
Registers the current reaction as dependent on this Dependency.
dependency.depend()
import { Dependency, Reaction } from '@semantic-ui/reactivity';
const dep = new Dependency();
Reaction.create(() => { dep.depend(); console.log('This will re-run when dep.changed() is called');});
Notifies all dependent reactions that this dependency has changed, causing them to re-run.
dependency.changed(context)
Name | Type | Description |
---|---|---|
context | any | (Optional) Additional context information to pass to invalidated reactions |
import { Dependency, Reaction } from '@semantic-ui/reactivity';
const dep = new Dependency();
Reaction.create(() => { dep.depend(); console.log('Reaction ran');});
dep.changed(); // Triggers the reaction to re-run
Removes a specific reaction from this dependency’s list of dependents.
dependency.cleanUp(reaction)
Name | Type | Description |
---|---|---|
reaction | Reaction | The reaction to remove from the dependency list |
import { Dependency, Reaction } from '@semantic-ui/reactivity';
const dep = new Dependency();
const reaction = Reaction.create(() => { dep.depend(); console.log('Reaction ran');});
// Later, when you want to remove this specific reaction:dep.cleanUp(reaction);
Alias for cleanUp
. Removes a specific reaction from this dependency’s list of dependents.
dependency.unsubscribe(reaction)
Name | Type | Description |
---|---|---|
reaction | Reaction | The reaction to unsubscribe from the dependency |
import { Dependency, Reaction } from '@semantic-ui/reactivity';
const dep = new Dependency();
const reaction = Reaction.create(() => { dep.depend(); console.log('Reaction ran');});
// Later, when you want to unsubscribe this specific reaction:dep.unsubscribe(reaction);