stream method

Stream<Resource<V>> stream(
  1. K key, {
  2. bool? forceReload,
  3. void doOnStore(
    1. V
    )?,
  4. ResourceFetchArguments? fetchArguments,
  5. bool allowEmptyLoading = false,
})

Creates a stream by key. It emits the cached data, then the fetch result if provided, and after that any changes to the resource due to reloading or invalidating the resource.

Implementation

Stream<Resource<V>> stream(
  K key, {
  bool? forceReload,
  void Function(V)? doOnStore,
  ResourceFetchArguments? fetchArguments,
  bool allowEmptyLoading = false,
}) {
  final force = forceReload ?? _firstLoad[key] ?? true;
  _firstLoad[key] = false;
  return _ensureResource(key)
      .asStream()
      .switchMap((resource) => resource.load(
            forceReload: force,
            doOnStore: doOnStore,
            allowEmptyLoading: allowEmptyLoading,
            fetchArguments: fetchArguments,
          ));
}