UseCompute<T> class

A ReactterHook that allows to compute a value using a predetermined compute function and a list of state dependencies, and which automatically updates the computed value if a dependency changes.

This example produces one simple UseCompute:

class AppController {
  final stateA = UseState(1);
  final stateB = UseState(7);
  late final computeState = UseCompute(
    () => (stateA + stateB).clamp(10, 15),
    [stateA, stateB],
  );

  AppController() {
    print(computeState.value); // 10;

    UseEffect((){
      print(computeState.value);
      // will print: 11, 15, 11
    }, [computeState]);

    stateA.value += 1; // numClamp doesn't change, its value is 10
    stateB.value += 2; // numClamp changes, its value is 11
    stateA.value += 4; // numClamp changes, its value is 15
    stateB.value += 8; // numClamp doesn't change, its value is 15
    stateA.value -= 8; // numClamp doesn't change, its value is 15
    stateB.value -= 4; // numClamp changes, its value is 11
  }
}
Inheritance

Constructors

UseCompute(T compute(), List<ReactterState> dependencies)
A ReactterHook that allows to compute a value using a predetermined compute function and a list of state dependencies, and which automatically updates the computed value if a dependency changes.

Properties

$ → HookRegister
This variable is used to register Hook and attach the StateBase that are defined here.
final
compute → T Function()
final
dependencies List<ReactterState>
final
eventManager → EventManager
no setterinherited
hashCode int
The hash code for this object.
no setterinherited
instanceBinded Object?
The reference instance to the current state.
no setterinherited
instanceManager → InstanceManager
no setterinherited
isDisposed bool
Returns true if the state has been disposed.
no setterinherited
logger → Logger
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
stateManager → StateManager<StateBase>
no setterinherited
value → T
no setter

Methods

bind(Object instance) → void
Stores a reference to an object instance
inherited
dispose() → void
Called when this object is removed
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
refresh() → void
It's used to notify listeners that the state has been updated. It is typically called after making changes to the state object.
inherited
toString() String
A string representation of this object.
inherited
unbind() → void
Removes the reference to the object instance
inherited
update([covariant Function? callback]) → void
Executes callback, and notifies the listeners about the update.
inherited

Operators

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