addEffect method
Adds an effect that runs whenever the list changes.
An effect is a function that gets called when the list changes. It receives a Snapshot containing both the old and new list values.
Example:
final items = ['Item 1'].reactive;
// Add an effect to log changes
items.addEffect((snapshot) {
print('List changed: ${snapshot.oldValue} -> ${snapshot.newValue}');
});
// Add an effect to persist changes
items.addEffect((snapshot) {
saveToStorage('items', snapshot.newValue);
});
items.value.add('Item 2');
items.value = [...items.value]; // Both effects will trigger
Implementation
StreamSubscription<Snapshot<List<E>>> addEffect(
Function(Snapshot<List<E>>) effect) {
return stream.listen(effect);
}