1616 */
1717
1818import {
19- DataConnectSubscription ,
19+ OnCompleteSubscription ,
2020 OnErrorSubscription ,
2121 OnResultSubscription ,
2222 QueryPromise ,
@@ -39,6 +39,16 @@ import { setIfNotExists } from '../util/map';
3939
4040import { Code , DataConnectError } from './error' ;
4141
42+ /**
43+ * Representation of user provided subscription options.
44+ */
45+ interface DataConnectSubscription < Data , Variables > {
46+ userCallback : OnResultSubscription < Data , Variables > ;
47+ errCallback ?: ( e ?: DataConnectError ) => void ;
48+ onCompleteCallback ?: ( ) => void ;
49+ unsubscribe : ( ) => void ;
50+ }
51+
4252interface TrackedQuery < Data , Variables > {
4353 ref : Omit < OperationRef < Data , Variables > , 'dataConnect' > ;
4454 subscriptions : Array < DataConnectSubscription < Data , Variables > > ;
@@ -97,6 +107,7 @@ export class QueryManager {
97107 addSubscription < Data , Variables > (
98108 queryRef : OperationRef < Data , Variables > ,
99109 onResultCallback : OnResultSubscription < Data , Variables > ,
110+ onCompleteCallback ?: OnCompleteSubscription ,
100111 onErrorCallback ?: OnErrorSubscription ,
101112 initialCache ?: OpResult < Data >
102113 ) : ( ) => void {
@@ -111,13 +122,15 @@ export class QueryManager {
111122 > ;
112123 const subscription = {
113124 userCallback : onResultCallback ,
125+ onCompleteCallback,
114126 errCallback : onErrorCallback
115127 } ;
116128 const unsubscribe = ( ) : void => {
117129 const trackedQuery = this . _queries . get ( key ) ! ;
118130 trackedQuery . subscriptions = trackedQuery . subscriptions . filter (
119131 sub => sub !== subscription
120132 ) ;
133+ onCompleteCallback ?.( ) ;
121134 } ;
122135 if ( initialCache && trackedQuery . currentCache !== initialCache ) {
123136 logDebug ( 'Initial cache found. Comparing dates.' ) ;
0 commit comments