A mixin that adds tracking for the initial and previous values to a Signal.
TrackedSignalMixin stores the initialValue (the value the signal had when it was
created or initialized) and the previousValue (the value of the signal right before
the most recent update).
Example Usage#
import 'package:signals/signals.dart';
class MyTrackedSignal extends Signal<int> with TrackedSignalMixin<int> {
MyTrackedSignal(super.internalValue);
}
void main() {
final signal = MyTrackedSignal(0);
print('Initial: ${signal.initialValue}'); // Prints: "Initial: 0"
print('Previous: ${signal.previousValue}'); // Prints: "Previous: null"
signal.value = 1;
print('Initial: ${signal.initialValue}'); // Prints: "Initial: 0"
print('Previous: ${signal.previousValue}'); // Prints: "Previous: 0"
signal.value = 2;
print('Initial: ${signal.initialValue}'); // Prints: "Initial: 0"
print('Previous: ${signal.previousValue}'); // Prints: "Previous: 1"
}
initialValue and
previousValue will end up pointing to the same modified instance as the current value.
Methods#
View Methods
T initialValue
The initial value the signal was created with
T? previousValue
Get the previous value (if exists)
trackedSignal#
Create a signal that stores the initial and previous value
TrackedSignal#
A signal that stores the initial and previous value
Constructors#
View Constructors
TrackedSignal(super.value, {TrackedSignalOptions? options, @Deprecated('Use options: TrackedSignalOptions(autoDispose: ...) instead') bool? autoDispose, @Deprecated('Use options: TrackedSignalOptions(name: ...) instead') String? debugLabel})
A signal that stores the initial and previous value
TrackedSignalOptions#
Configuration options for a TrackedSignal.
Constructors#
View Constructors
TrackedSignalOptions({super.name, super.autoDispose, super.watched, super.unwatched})
Creates a new TrackedSignalOptions instance.