coralOf<T> method

  1. @protected
Coral<T> coralOf<T>()

Reactively subscribes to an ancestor InheritedCoralProviderWidget and unwraps its inner Coral<T> state.

Locates the nearest InheritedCoralProviderWidget providing type T in the ancestor tree and flattens its underlying pipeline into a unified reactive stream.

Key Architectural Advantages of coralOf<T>():

  1. Lazy Computation (Push-Dirty, Pull-Data): Eliminates UI frame drops (jank) by delaying computations strictly until frame render time.
  2. Context Decoupling via Intent Architecture: Accesses ancestor state within business class fields without storing or leaking BuildContext references.
  3. Cascade Stream Flattening (2-Axis Unwrapping): Internally evaluates as: dependOn<InheritedCoralProviderWidget<T>>().cascade((data) => data.provider.coral) Flattens both ancestor tree position updates and internal state mutations into a single, unified Coral<T> stream.
  4. Topological Graph Safety (@manifestSync): Guarantees zero-over-fetching state synchronization when declared in manifest().

Requires:

Ensures:

  • Automatically tracks changes to both the ancestor widget tree and the inner Coral<T> state.
  • Returns a non-null reactive Coral<T> pipeline.

Throws:

Example:

class CounterDisplay extends ComplexComputation<Widget> with CorallineBuildContextAware {
  late final counterState = coralOf<CounterState>();
}

Implementation

@protected
@pragma('vm:prefer-inline')
Coral<T> coralOf<T>() {
  return dependOn<InheritedCoralProviderWidget<T>>()
      .cascade((data) => data.provider.coral);
}