LogoSignals.dart
Copy Markdown
rodydavis/signals.dart 999999

TrackedSignalMixin

A mixin that adds tracking for the initial and previous values to a Signal.

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).

If you are looking for full undo/redo capabilities, use ChangeStackSignalMixin instead.

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"
}
This mixin only works with values that are immutable or are copied/cloned on mutation. If the value is mutated directly in-place without re-assigning, 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.

Methods#

View Methods
TrackedSignalOptions copyWith({String? name, bool? autoDispose, void Function()? watched, void Function()? unwatched})
bool ==(Object other)
int hashCode