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 iterable)
void addFirst(T value)
void addLast(T value)
bool any(bool Function(T element) test)
Queue cast()
void clear()
bool contains(Object? element)
T elementAt(int index)
bool every(bool Function(T element) test)
Iterable expand(Iterable 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 followedBy(Iterable other)
void forEach(void Function(T element) action)
bool isEmpty
bool isNotEmpty
Iterator iterator
String join([String separator = ""])
T last
T lastWhere(bool Function(T element) test, {T Function()? orElse})
int length
Iterable 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 skip(int count)
Iterable skipWhile(bool Function(T value) test)
Iterable take(int count)
Iterable takeWhile(bool Function(T value) test)
List toList({bool growable = true})
Set toSet()
Iterable where(bool Function(T element) test)
Iterable whereType()

SignalQueueUtils#

Utility extension methods on Queue to convert them to QueueSignals.

Methods#

View Methods
QueueSignal toSignal({QueueSignalOptions? options, @Deprecated('Use options: QueueSignalOptions(autoDispose: ...) instead') bool? autoDispose, @Deprecated('Use options: QueueSignalOptions(name: ...) instead') String? debugLabel})

Convert an existing list to QueueSignal


queueSignal#

Creates a QueueSignal with the given list (Queue).


QueueSignalOptions#

Configuration options for a QueueSignal.

Constructors#

View Constructors
QueueSignalOptions({super.name, super.autoDispose, super.watched, super.unwatched, super.equality = const SignalDeepEquality()})

Creates a new QueueSignalOptions instance.

Methods#

View Methods
QueueSignalOptions copyWith({String? name, bool? autoDispose, void Function()? watched, void Function()? unwatched, SignalEquality<Queue>? equality})
bool ==(Object other)
int hashCode

QueueSignal#

A Signal that holds a Queue.

Constructors#

View Constructors
QueueSignal(super.value, {QueueSignalOptions? options, @Deprecated('Use options: QueueSignalOptions(autoDispose: ...) instead') bool? autoDispose, @Deprecated('Use options: QueueSignalOptions(name: ...) instead') String? debugLabel})

Creates a QueueSignal with the given value.