@@ -16,13 +16,16 @@ import { DBShowStyleBase } from '@sofie-automation/corelib/dist/dataModel/ShowSt
1616import { logger } from '../../logging'
1717import { observerChain } from '../../publications/lib/observerChain'
1818import { ContentCache } from './reactiveContentCache'
19+ import { ContentCache as PieceInstancesContentCache } from './reactiveContentCacheForPieceInstances'
1920import { RundownContentObserver } from './RundownContentObserver'
2021import { RundownsObserver } from './RundownsObserver'
2122import { RundownPlaylists , Rundowns , ShowStyleBases } from '../../collections'
2223import { PromiseDebounce } from '../../publications/lib/PromiseDebounce'
2324import { MinimalMongoCursor } from '../../collections/implementations/asyncCollection'
25+ import { PieceInstancesObserver } from './PieceInstancesObserver'
2426
25- type ChangedHandler = ( showStyleBaseId : ShowStyleBaseId , cache : ContentCache ) => ( ) => void
27+ type RundownContentChangeHandler = ( showStyleBaseId : ShowStyleBaseId , cache : ContentCache ) => ( ) => void
28+ type PieceInstancesChangeHandler = ( showStyleBaseId : ShowStyleBaseId , cache : PieceInstancesContentCache ) => ( ) => void
2629
2730const REACTIVITY_DEBOUNCE = 20
2831
@@ -60,18 +63,26 @@ export class StudioObserver extends EventEmitter {
6063 #playlistInStudioLiveQuery: Meteor . LiveQueryHandle
6164 #showStyleOfRundownLiveQuery: Meteor . LiveQueryHandle | undefined
6265 #rundownsLiveQuery: Meteor . LiveQueryHandle | undefined
66+ #pieceInstancesLiveQuery: Meteor . LiveQueryHandle | undefined
67+
6368 showStyleBaseId : ShowStyleBaseId | undefined
6469
6570 currentProps : StudioObserverProps | undefined = undefined
6671 nextProps : StudioObserverProps | undefined = undefined
6772
68- #changed: ChangedHandler
73+ #rundownContentChanged: RundownContentChangeHandler
74+ #pieceInstancesChanged: PieceInstancesChangeHandler
6975
7076 #disposed = false
7177
72- constructor ( studioId : StudioId , onChanged : ChangedHandler ) {
78+ constructor (
79+ studioId : StudioId ,
80+ onRundownContentChanged : RundownContentChangeHandler ,
81+ pieceInstancesChanged : PieceInstancesChangeHandler
82+ ) {
7383 super ( )
74- this . #changed = onChanged
84+ this . #rundownContentChanged = onRundownContentChanged
85+ this . #pieceInstancesChanged = pieceInstancesChanged
7586 this . #playlistInStudioLiveQuery = observerChain ( )
7687 . next (
7788 'activePlaylist' ,
@@ -172,6 +183,9 @@ export class StudioObserver extends EventEmitter {
172183 this . #rundownsLiveQuery?. stop ( )
173184 this . #rundownsLiveQuery = undefined
174185 this . showStyleBaseId = showStyleBaseId
186+
187+ this . #pieceInstancesLiveQuery?. stop ( )
188+ this . #pieceInstancesLiveQuery = undefined
175189 return
176190 }
177191
@@ -186,28 +200,42 @@ export class StudioObserver extends EventEmitter {
186200 this . #rundownsLiveQuery?. stop ( )
187201 this . #rundownsLiveQuery = undefined
188202
203+ this . #pieceInstancesLiveQuery?. stop ( )
204+ this . #pieceInstancesLiveQuery = undefined
205+
206+ this . showStyleBaseId = showStyleBaseId
207+
189208 this . currentProps = this . nextProps
190209 this . nextProps = undefined
191210
192- const { activePlaylistId } = this . currentProps
211+ const { activePlaylistId, activationId } = this . currentProps
193212
194213 this . showStyleBaseId = showStyleBaseId
195214
196215 this . #rundownsLiveQuery = await RundownsObserver . create ( activePlaylistId , async ( rundownIds ) => {
197216 logger . silly ( `Creating new RundownContentObserver` )
198217
199218 const obs1 = await RundownContentObserver . create ( activePlaylistId , showStyleBaseId , rundownIds , ( cache ) => {
200- return this . #changed ( showStyleBaseId , cache )
219+ return this . #rundownContentChanged ( showStyleBaseId , cache )
201220 } )
202221
203222 return ( ) => {
204223 obs1 . stop ( )
205224 }
206225 } )
207226
227+ this . #pieceInstancesLiveQuery = await PieceInstancesObserver . create ( activationId , showStyleBaseId , ( cache ) => {
228+ const cleanupChanges = this . #pieceInstancesChanged( showStyleBaseId , cache )
229+
230+ return ( ) => {
231+ cleanupChanges ?.( )
232+ }
233+ } )
234+
208235 if ( this . #disposed) {
209236 // If we were disposed of while waiting for the observer to be created, stop it immediately
210237 this . #rundownsLiveQuery. stop ( )
238+ this . #pieceInstancesLiveQuery. stop ( )
211239 }
212240 } , REACTIVITY_DEBOUNCE )
213241
0 commit comments