snapshots method

  1. @override
Observable<Iterable<Map<String, DocumentReference?>>> snapshots({
  1. bool subscribe = true,
})
override

Returns an observable that emits the query results and updates whenever the query results change unless subscribe=false is provided.

Important: Make sure to unsubscribe from the observable when you are done with it.

Implementation

@override
Observable<Iterable<Map<String, DocumentReference?>>> snapshots(
        {bool subscribe = true}) =>
    _querySubscriptionManager
        .processQuery(
            build(),
            _rootAlias,
            _joins.map((key, value) => MapEntry(key, value.copyWith())),
            _joinConditions
                .map((key, value) => MapEntry(key, value.copyWith())),
            subscribe,
            false)
        .map((docs) => docs.map((docRecord) {
              final result = <String, DocumentReference?>{};
              for (final entry in docRecord.entries) {
                final alias = entry.key;
                final doc = entry.value;
                final collectionName = alias == _rootAlias
                    ? _collectionName
                    : _joins[alias]!.collectionName;
                final integrationId = alias == _rootAlias
                    ? _integrationId
                    : _joins[alias]!.integrationId;
                final squidDocId = doc != null
                    ? SquidDocIdObj(
                            collectionName: collectionName,
                            docId: doc["__docId__"],
                            integrationId: integrationId)
                        .toSquidDocId()
                    : null;
                result[alias] = squidDocId != null
                    ? _documentReferenceFactory.create(
                        squidDocId, _queryBuilderFactory)
                    : null;
              }
              return result;
            }));