(
private collection: CollectionImpl<any, any, any, any, any>,
private callback: (changes: Array<ChangeMessage<any, any>>) => void,
private options: CollectionSubscriptionOptions,
)
| 106 | } |
| 107 | |
| 108 | constructor( |
| 109 | private collection: CollectionImpl<any, any, any, any, any>, |
| 110 | private callback: (changes: Array<ChangeMessage<any, any>>) => void, |
| 111 | private options: CollectionSubscriptionOptions, |
| 112 | ) { |
| 113 | super() |
| 114 | if (options.onUnsubscribe) { |
| 115 | this.on(`unsubscribed`, (event) => options.onUnsubscribe!(event)) |
| 116 | } |
| 117 | |
| 118 | // Auto-index for where expressions if enabled |
| 119 | if (options.whereExpression) { |
| 120 | ensureIndexForExpression(options.whereExpression, this.collection) |
| 121 | } |
| 122 | |
| 123 | const callbackWithSentKeysTracking = ( |
| 124 | changes: Array<ChangeMessage<any, any>>, |
| 125 | ) => { |
| 126 | callback(changes) |
| 127 | this.trackSentKeys(changes) |
| 128 | } |
| 129 | |
| 130 | this.callback = callbackWithSentKeysTracking |
| 131 | |
| 132 | // Create a filtered callback if where clause is provided |
| 133 | this.filteredCallback = options.whereExpression |
| 134 | ? createFilteredCallback(this.callback, options) |
| 135 | : this.callback |
| 136 | |
| 137 | // Listen for truncate events to re-request data after must-refetch |
| 138 | // When a truncate happens (e.g., from a 409 must-refetch), all collection data is cleared. |
| 139 | // We need to re-request all previously loaded subsets to repopulate the data. |
| 140 | this.truncateCleanup = this.collection.on(`truncate`, () => { |
| 141 | this.handleTruncate() |
| 142 | }) |
| 143 | } |
| 144 | |
| 145 | /** |
| 146 | * Handle collection truncate event by resetting state and re-requesting subsets. |
nothing calls this directly
no test coverage detected