onData method

void Function() onData(
  1. Iterable<OnData<TParsed>> callbacks, {
  2. bool removeAfterInvocation = true,
})

Register callbacks to trigger when stream has new results where QueryResult.isNotLoading

Will deregister callbacks after calling them on the first result that QueryResult.isConcrete, handling the resolution of lifecycle from QueryLifecycle.sideEffectsBlocking to QueryLifecycle.completed as appropriate, unless if removeAfterInvocation is set to false.

Returns a function for removing the added callbacks

Implementation

void Function() onData(
  Iterable<OnData<TParsed>> callbacks, {
  bool removeAfterInvocation = true,
}) {
  _onDataCallbacks.addAll(callbacks);

  if (!removeAfterInvocation) {
    _notRemovableOnDataCallbacks.addAll(callbacks);
  }

  return () {
    _onDataCallbacks.removeWhere((cb) => callbacks.contains(cb));
    _notRemovableOnDataCallbacks.removeWhere((cb) => callbacks.contains(cb));
  };
}