Collections

A @Signal field that holds a List, a Set, a Map or a Queue is handed out as a collection that tells its readers of a change in place.

Why

A list is rarely assigned: it is added to, sorted, cleared. If only an assignment were a change, every method would end with items = [...items], and one forgotten would leave the screen stale.

Example

@Signal()
List<Book> items = [];

void add(Book book) => items.add(book);     // told, without an assignment

What is a change

void remove(String title) => items = [
  for (final book in items)
    if (book.title != title) book,
];

One change in place is told once, however many elements it moved. A Set tells only of what changed it: adding an element already there tells nobody.

What stays

The field keeps the collection itself, and its type stays what was written: basket.items is a List<Book>.

See also