LogoSignals.dart
Copy Markdown
rodydavis/signals.dart 999999

QueueSignalMixin

A mixin that adds reactive <code>Queue</code> methods and operations to a Signal.

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.

Methods#

View Methods
void add(T value)
void addAll(Iterable<T> iterable)
void addFirst(T value)
void addLast(T value)
bool any(bool Function(T element) test)
Queue<R> cast()
void clear()
bool contains(Object? element)
T elementAt(int index)
bool every(bool Function(T element) test)
Iterable<U> expand(Iterable<U> Function(T element) toElements)
T first
T firstWhere(bool Function(T element) test, {T Function()? orElse})
U fold(U initialValue, U Function(U previousValue, T element) combine)
Iterable<T> followedBy(Iterable<T> other)
void forEach(void Function(T element) action)
bool isEmpty
bool isNotEmpty
Iterator<T> iterator
String join([String separator = ""])
T last
T lastWhere(bool Function(T element) test, {T Function()? orElse})
int length
Iterable<U> map(U Function(T e) toElement)
T reduce(T Function(T value, T element) combine)
bool remove(Object? value)
T removeFirst()
T removeLast()
void removeWhere(bool Function(T element) test)
void retainWhere(bool Function(T element) test)
T single
T singleWhere(bool Function(T element) test, {T Function()? orElse})
Iterable<T> skip(int count)
Iterable<T> skipWhile(bool Function(T value) test)
Iterable<T> take(int count)
Iterable<T> takeWhile(bool Function(T value) test)
List<T> toList({bool growable = true})
Set<T> toSet()
Iterable<T> where(bool Function(T element) test)
Iterable<U> whereType()