build method
Implementation
@override
Future<EntityListSnapshot<T>> build({
required String type,
required String queryKey,
required EntityDecoder<T> fromGraph,
EntityEncoder<T>? toGraph,
ListQuery query = const ListQuery(),
ViewCompleteness completeness = ViewCompleteness.remote,
bool enabled = true,
bool subscribe = true,
}) async {
_disposed = false;
_ready = false;
final graph = ref.watch(entityGraphProvider);
_viewRegistration?.dispose();
_viewRegistration = graph.registerView(
GraphViewDefinition(
viewId: 'entity-list:${type.length}:$type:$queryKey',
label: '$type list',
kind: GraphViewKind.list,
entityType: type,
queryKey: queryKey,
),
);
if (subscribe) {
ref.watch(entityChangeBridgeProvider<T>(type: type));
}
await _graphSubscription?.cancel();
_graphSubscription = graph.changes.listen(_onGraphChange);
ref.onDispose(() {
_disposed = true;
_viewRegistration?.dispose();
unawaited(_graphSubscription?.cancel());
});
if (!enabled || completeness == ViewCompleteness.local) {
_ready = true;
return _buildSnapshot(graph);
}
if (completeness == ViewCompleteness.hybrid) {
_ready = true;
unawaited(_loadHybrid(graph));
return _buildSnapshot(graph);
}
await _doFetch(graph);
_ready = true;
return _buildSnapshot(graph);
}