@@ -82,12 +82,13 @@ export class PieceInstancesHandler
82
82
}
83
83
if (
84
84
! areElementsShallowEqual ( this . _collectionData . currentPartInstance , inCurrentPartInstance ) &&
85
- this . _collectionData . currentPartInstance . some ( ( pieceInstance , index ) => {
86
- return ! arePropertiesShallowEqual < PieceInstance > ( inCurrentPartInstance [ index ] , pieceInstance , [
87
- 'reportedStartedPlayback' ,
88
- 'reportedStoppedPlayback' ,
89
- ] )
90
- } )
85
+ ( this . _collectionData . currentPartInstance . length !== inCurrentPartInstance . length ||
86
+ this . _collectionData . currentPartInstance . some ( ( pieceInstance , index ) => {
87
+ return ! arePropertiesShallowEqual < PieceInstance > ( inCurrentPartInstance [ index ] , pieceInstance , [
88
+ 'reportedStartedPlayback' ,
89
+ 'reportedStoppedPlayback' ,
90
+ ] )
91
+ } ) )
91
92
) {
92
93
this . _collectionData . currentPartInstance = inCurrentPartInstance
93
94
hasAnythingChanged = true
@@ -153,22 +154,30 @@ export class PieceInstancesHandler
153
154
void this . changed ( id , 'removed' ) . catch ( this . _logger . error )
154
155
}
155
156
156
- const hasAnythingChanged = this . updateCollectionData ( )
157
- if ( hasAnythingChanged ) {
158
- await this . notify ( this . _collectionData )
159
- }
157
+ await this . updateAndNotify ( )
160
158
} else if ( this . _subscriptionId ) {
161
- // nothing relevant has changed
159
+ await this . updateAndNotify ( )
162
160
} else {
163
- this . clearCollectionData ( )
164
- await this . notify ( this . _collectionData )
161
+ await this . clearAndNotify ( )
165
162
}
166
163
} else {
167
164
this . clearCollectionData ( )
168
165
await this . notify ( this . _collectionData )
169
166
}
170
167
}
171
168
169
+ private async clearAndNotify ( ) {
170
+ this . clearCollectionData ( )
171
+ await this . notify ( this . _collectionData )
172
+ }
173
+
174
+ private async updateAndNotify ( ) {
175
+ const hasAnythingChanged = this . updateCollectionData ( )
176
+ if ( hasAnythingChanged ) {
177
+ await this . notify ( this . _collectionData )
178
+ }
179
+ }
180
+
172
181
private isPieceInstanceActive ( pieceInstance : PieceInstance ) {
173
182
return (
174
183
pieceInstance . reportedStoppedPlayback == null &&
@@ -187,7 +196,7 @@ export function arePropertiesShallowEqual<T extends Record<string, any>>(
187
196
b : T ,
188
197
omitProperties : Array < keyof T >
189
198
) : boolean {
190
- if ( typeof a !== 'object' || a === null || typeof b !== 'object' || b = == null ) {
199
+ if ( typeof a !== 'object' || a == null || typeof b !== 'object' || b == null ) {
191
200
return false
192
201
}
193
202
0 commit comments