JoltSetupContext<T extends Widget> class

The core context that manages hooks and reactive state for setup-based widgets.

This context extends EffectScopeImpl to provide automatic cleanup of reactive nodes when the widget is disposed. It manages the complete hook lifecycle including creation, update, and hot reload support.

Design

JoltSetupContext is intentionally decoupled from both Element and State, making it reusable across different widget implementations:

While the external API (setup function signature) remains consistent across implementations, the internal build trigger mechanisms differ to leverage the specific advantages of Element (markNeedsBuild) vs State (setState).

Responsibilities

  • Manages hook registration and lifecycle (_useHook, unmountHooks)
  • Handles hot reload with hook sequence matching (_reload)
  • Provides reactive scope for setup functions (run)
  • Stores the widget builder and renderer effect
  • Notifies hooks of lifecycle events (notifyUpdate, notifyDependenciesChanged, etc.)

Hot Reload

During hot reload, hooks are matched by runtime type and position:

  1. Matching hooks preserve their state and receive SetupHook.reassemble
  2. Mismatched hooks are unmounted and replaced with new instances
  3. New hooks receive SetupHook.mount after setup completes
Inheritance

Constructors

JoltSetupContext(BuildContext context, PropsReadonlyNode<T> propsNode)

Properties

context BuildContext
final
deps Link?
First dependency link in the chain.
getter/setter pairinherited
depsTail Link?
Last dependency link in the chain.
getter/setter pairinherited
flags int
Reactive flags for this node.
getter/setter pairinherited
hashCode int
The hash code for this object.
no setterinherited
isDisposed bool
no setterinherited
propsNode PropsReadonlyNode<T>
final
renderer Effect?
The effect that triggers widget rebuilds when reactive dependencies change.
getter/setter pair
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
setupBuilder WidgetFunction<T>?
The setup function that returns the widget builder.
getter/setter pair
subs Link?
First subscriber link in the chain.
getter/setter pairinherited
subsTail Link?
Last subscriber link in the chain.
getter/setter pairinherited

Methods

dispose() → void
Disposes this node and cleans up resources.
inherited
doCleanup() → void
Executes all registered cleanup functions and clears the cleanup list.
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
notifyActivated() → void
Notifies all hooks that the widget has been activated.
notifyDeactivated() → void
Notifies all hooks that the widget has been deactivated.
notifyDependenciesChanged() → void
Notifies all hooks that dependencies have changed.
notifyUpdate() → void
Notifies props node and all hooks that the widget has been updated.
onCleanUp(Disposer fn) → void
Registers a cleanup function to be called when this effect is disposed or re-run.
inherited
onDispose() → void
Called during the disposal process to perform custom cleanup.
override
run<U>(U fn()) → U
Runs a function within this scope's context.
override
toString() String
A string representation of this object.
inherited
unmountHooks() → void
Unmounts all hooks in reverse order.

Operators

operator ==(Object other) bool
The equality operator.
inherited

Static Properties

current JoltSetupContext<Widget>?
getter/setter pair

Static Methods

setActiveContext([JoltSetupContext<Widget>? context]) JoltSetupContext<Widget>?