A mixin that adds reactive Queue methods and operations to a Signal
holding a Queue value.
This mixin delegates all standard Queue operations (such as mutations like add,
addAll, addFirst, addLast, removeFirst,
removeLast, and clear) to the
underlying queue, while ensuring that any reads register a dependency and any
mutations automatically trigger reactive updates.
This mixin only works with signals that have a value type extending **Queue**.
Example Usage#
import 'dart:collection';
import 'package:signals/signals.dart';
class MyQueueSignal extends Signal<Queue<int>>
with QueueSignalMixin<int, Queue<int>> {
MyQueueSignal(super.internalValue);
}
void main() {
final q = Queue<int>()..add(1);
final signal = MyQueueSignal(q);
effect(() {
print('Queue elements: $signal, Length: ${signal.length}');
}); // Prints: "Queue elements: {1}, Length: 1"
// Adding to the front of the queue (triggers updates)
signal.addFirst(0); // Prints: "Queue elements: {0, 1}, Length: 2"
// Adding to the back of the queue (triggers updates)
signal.addLast(2); // Prints: "Queue elements: {0, 1, 2}, Length: 3"
// Removing from the front of the queue (triggers updates)
final first = signal.removeFirst(); // Prints: "Queue elements: {1, 2}, Length: 2"
}
Since mutations on
QueueSignalMixin notify listeners automatically, you do not
need to assign signal.value = ... to force updates. Methods like addFirst,
addLast, removeFirst, and removeLast take care of notification.