@@ -23,6 +23,7 @@ import {
2323 rundownPlaylistFieldSpecifier ,
2424 segmentFieldSpecifier ,
2525} from './reactiveContentCache'
26+ import { waitForAllObserversReady } from '../../publications/lib/lib'
2627
2728const REACTIVITY_DEBOUNCE = 20
2829
@@ -37,41 +38,56 @@ export class RundownContentObserver {
3738 }
3839 #disposed = false
3940
40- constructor (
41- rundownPlaylistId : RundownPlaylistId ,
42- showStyleBaseId : ShowStyleBaseId ,
43- rundownIds : RundownId [ ] ,
44- onChanged : ChangedHandler
45- ) {
46- logger . silly ( `Creating RundownContentObserver for playlist "${ rundownPlaylistId } "` )
41+ private constructor ( onChanged : ChangedHandler ) {
4742 const { cache, cancel : cancelCache } = createReactiveContentCache ( ( ) => {
4843 this . #cleanup = onChanged ( cache )
4944 if ( this . #disposed) this . #cleanup( )
5045 } , REACTIVITY_DEBOUNCE )
5146
5247 this . #cache = cache
5348 this . #cancelCache = cancelCache
49+ }
50+
51+ static async create (
52+ rundownPlaylistId : RundownPlaylistId ,
53+ showStyleBaseId : ShowStyleBaseId ,
54+ rundownIds : RundownId [ ] ,
55+ onChanged : ChangedHandler
56+ ) : Promise < RundownContentObserver > {
57+ logger . silly ( `Creating RundownContentObserver for playlist "${ rundownPlaylistId } "` )
58+
59+ const observer = new RundownContentObserver ( onChanged )
60+
61+ await observer . initObservers ( rundownPlaylistId , showStyleBaseId , rundownIds )
5462
55- this . #observers = [
56- RundownPlaylists . observeChanges ( rundownPlaylistId , cache . RundownPlaylists . link ( ) , {
63+ return observer
64+ }
65+
66+ private async initObservers (
67+ rundownPlaylistId : RundownPlaylistId ,
68+ showStyleBaseId : ShowStyleBaseId ,
69+ rundownIds : RundownId [ ]
70+ ) {
71+ this . #observers = await waitForAllObserversReady ( [
72+ RundownPlaylists . observeChanges ( rundownPlaylistId , this . #cache. RundownPlaylists . link ( ) , {
5773 projection : rundownPlaylistFieldSpecifier ,
5874 } ) ,
59- ShowStyleBases . observeChanges ( showStyleBaseId , cache . ShowStyleBases . link ( ) ) ,
75+ ShowStyleBases . observeChanges ( showStyleBaseId , this . # cache. ShowStyleBases . link ( ) ) ,
6076 TriggeredActions . observeChanges (
6177 {
6278 showStyleBaseId : {
6379 $in : [ showStyleBaseId , null ] ,
6480 } ,
6581 } ,
66- cache . TriggeredActions . link ( )
82+ this . # cache. TriggeredActions . link ( )
6783 ) ,
6884 Segments . observeChanges (
6985 {
7086 rundownId : {
7187 $in : rundownIds ,
7288 } ,
7389 } ,
74- cache . Segments . link ( ) ,
90+ this . # cache. Segments . link ( ) ,
7591 {
7692 projection : segmentFieldSpecifier ,
7793 }
@@ -82,7 +98,7 @@ export class RundownContentObserver {
8298 $in : rundownIds ,
8399 } ,
84100 } ,
85- cache . Parts . link ( ) ,
101+ this . # cache. Parts . link ( ) ,
86102 {
87103 projection : partFieldSpecifier ,
88104 }
@@ -96,7 +112,7 @@ export class RundownContentObserver {
96112 $ne : true ,
97113 } ,
98114 } ,
99- cache . PartInstances . link ( ) ,
115+ this . # cache. PartInstances . link ( ) ,
100116 {
101117 projection : partInstanceFieldSpecifier ,
102118 }
@@ -107,7 +123,7 @@ export class RundownContentObserver {
107123 $in : rundownIds ,
108124 } ,
109125 } ,
110- cache . RundownBaselineAdLibActions . link ( ) ,
126+ this . # cache. RundownBaselineAdLibActions . link ( ) ,
111127 {
112128 projection : adLibActionFieldSpecifier ,
113129 }
@@ -118,7 +134,7 @@ export class RundownContentObserver {
118134 $in : rundownIds ,
119135 } ,
120136 } ,
121- cache . RundownBaselineAdLibPieces . link ( ) ,
137+ this . # cache. RundownBaselineAdLibPieces . link ( ) ,
122138 {
123139 projection : adLibPieceFieldSpecifier ,
124140 }
@@ -129,7 +145,7 @@ export class RundownContentObserver {
129145 $in : rundownIds ,
130146 } ,
131147 } ,
132- cache . AdLibActions . link ( ) ,
148+ this . # cache. AdLibActions . link ( ) ,
133149 {
134150 projection : adLibActionFieldSpecifier ,
135151 }
@@ -140,12 +156,12 @@ export class RundownContentObserver {
140156 $in : rundownIds ,
141157 } ,
142158 } ,
143- cache . AdLibPieces . link ( ) ,
159+ this . # cache. AdLibPieces . link ( ) ,
144160 {
145161 projection : adLibPieceFieldSpecifier ,
146162 }
147163 ) ,
148- ]
164+ ] )
149165 }
150166
151167 public get cache ( ) : ContentCache {
0 commit comments