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
-
- Object
- ReactterHook
- UseCompute
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
- $ → _ReactterHookRegister
-
This variable is used to register ReactterHook
and attach the ReactterState that are defined here.
final
- compute → T Function()
-
final
-
dependencies
→ List<
ReactterState> -
final
- hashCode → int
-
The hash code for this object.
no setterinherited
- instanceAttached → Object?
-
no setterinherited
- isDisposed → bool
-
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- value → T
-
no setter
Methods
-
attachTo(
Object instance) → void -
Attaches an object instance to this state.
inherited
-
detachInstance(
) → void -
Detaches an object instance to this state.
inherited
-
dispose(
) → void -
Called when this object is removed
override
-
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
-
update(
[covariant Function? callback]) → void -
Executes
callback
, and notify the listeners about to update.inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited