stream method
Stream<Resource<V> >
stream(
- K key, {
- bool? forceReload,
- void doOnStore(
- V
- ResourceFetchArguments? fetchArguments,
- 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,
));
}