@@ -16,13 +16,16 @@ import { DBShowStyleBase } from '@sofie-automation/corelib/dist/dataModel/ShowSt
16
16
import { logger } from '../../logging'
17
17
import { observerChain } from '../../publications/lib/observerChain'
18
18
import { ContentCache } from './reactiveContentCache'
19
+ import { ContentCache as PieceInstancesContentCache } from './reactiveContentCacheForPieceInstances'
19
20
import { RundownContentObserver } from './RundownContentObserver'
20
21
import { RundownsObserver } from './RundownsObserver'
21
22
import { RundownPlaylists , Rundowns , ShowStyleBases } from '../../collections'
22
23
import { PromiseDebounce } from '../../publications/lib/PromiseDebounce'
23
24
import { MinimalMongoCursor } from '../../collections/implementations/asyncCollection'
25
+ import { PieceInstancesObserver } from './PieceInstancesObserver'
24
26
25
- type ChangedHandler = ( showStyleBaseId : ShowStyleBaseId , cache : ContentCache ) => ( ) => void
27
+ type RundownContentChangeHandler = ( showStyleBaseId : ShowStyleBaseId , cache : ContentCache ) => ( ) => void
28
+ type PieceInstancesChangeHandler = ( showStyleBaseId : ShowStyleBaseId , cache : PieceInstancesContentCache ) => ( ) => void
26
29
27
30
const REACTIVITY_DEBOUNCE = 20
28
31
@@ -60,18 +63,26 @@ export class StudioObserver extends EventEmitter {
60
63
#playlistInStudioLiveQuery: Meteor . LiveQueryHandle
61
64
#showStyleOfRundownLiveQuery: Meteor . LiveQueryHandle | undefined
62
65
#rundownsLiveQuery: Meteor . LiveQueryHandle | undefined
66
+ #pieceInstancesLiveQuery: Meteor . LiveQueryHandle | undefined
67
+
63
68
showStyleBaseId : ShowStyleBaseId | undefined
64
69
65
70
currentProps : StudioObserverProps | undefined = undefined
66
71
nextProps : StudioObserverProps | undefined = undefined
67
72
68
- #changed: ChangedHandler
73
+ #rundownContentChanged: RundownContentChangeHandler
74
+ #pieceInstancesChanged: PieceInstancesChangeHandler
69
75
70
76
#disposed = false
71
77
72
- constructor ( studioId : StudioId , onChanged : ChangedHandler ) {
78
+ constructor (
79
+ studioId : StudioId ,
80
+ onRundownContentChanged : RundownContentChangeHandler ,
81
+ pieceInstancesChanged : PieceInstancesChangeHandler
82
+ ) {
73
83
super ( )
74
- this . #changed = onChanged
84
+ this . #rundownContentChanged = onRundownContentChanged
85
+ this . #pieceInstancesChanged = pieceInstancesChanged
75
86
this . #playlistInStudioLiveQuery = observerChain ( )
76
87
. next (
77
88
'activePlaylist' ,
@@ -172,6 +183,9 @@ export class StudioObserver extends EventEmitter {
172
183
this . #rundownsLiveQuery?. stop ( )
173
184
this . #rundownsLiveQuery = undefined
174
185
this . showStyleBaseId = showStyleBaseId
186
+
187
+ this . #pieceInstancesLiveQuery?. stop ( )
188
+ this . #pieceInstancesLiveQuery = undefined
175
189
return
176
190
}
177
191
@@ -186,25 +200,38 @@ export class StudioObserver extends EventEmitter {
186
200
this . #rundownsLiveQuery?. stop ( )
187
201
this . #rundownsLiveQuery = undefined
188
202
203
+ this . #pieceInstancesLiveQuery?. stop ( )
204
+ this . #pieceInstancesLiveQuery = undefined
205
+
206
+ this . showStyleBaseId = showStyleBaseId
207
+
189
208
this . currentProps = this . nextProps
190
209
this . nextProps = undefined
191
210
192
- const { activePlaylistId } = this . currentProps
211
+ const { activePlaylistId, activationId } = this . currentProps
193
212
194
213
this . showStyleBaseId = showStyleBaseId
195
214
196
215
this . #rundownsLiveQuery = await RundownsObserver . create ( activePlaylistId , async ( rundownIds ) => {
197
216
logger . silly ( `Creating new RundownContentObserver` )
198
217
199
218
const obs1 = await RundownContentObserver . create ( activePlaylistId , showStyleBaseId , rundownIds , ( cache ) => {
200
- return this . #changed ( showStyleBaseId , cache )
219
+ return this . #rundownContentChanged ( showStyleBaseId , cache )
201
220
} )
202
221
203
222
return ( ) => {
204
223
obs1 . stop ( )
205
224
}
206
225
} )
207
226
227
+ this . #pieceInstancesLiveQuery = await PieceInstancesObserver . create ( activationId , showStyleBaseId , ( cache ) => {
228
+ const cleanupChanges = this . #pieceInstancesChanged( showStyleBaseId , cache )
229
+
230
+ return ( ) => {
231
+ cleanupChanges ?.( )
232
+ }
233
+ } )
234
+
208
235
if ( this . #disposed) {
209
236
// If we were disposed of while waiting for the observer to be created, stop it immediately
210
237
this . #rundownsLiveQuery. stop ( )
0 commit comments