Skip to content

Commit 1131a6b

Browse files
committed
wip: avoid nonreactive tracker
1 parent ceb36d0 commit 1131a6b

File tree

6 files changed

+90
-96
lines changed

6 files changed

+90
-96
lines changed

meteor/server/api/deviceTriggers/triggersContext.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import { MeteorCall } from '../methods'
66
import { ClientAPI } from '@sofie-automation/meteor-lib/dist/api/client'
77
import { UserAction } from '@sofie-automation/meteor-lib/dist/userAction'
88
import { TFunction } from 'i18next'
9-
import { Tracker } from 'meteor/tracker'
109

1110
import { logger } from '../../logging'
1211
import { IBaseFilterLink, IRundownPlaylistFilterLink } from '@sofie-automation/blueprints-integration'
@@ -67,8 +66,6 @@ export const MeteorTriggersContext: TriggersContext = {
6766
)
6867
},
6968

70-
nonreactiveTracker: Tracker.nonreactive,
71-
7269
memoizedIsolatedAutorun: async <TArgs extends any[], TRes>(
7370
fnc: (...args: TArgs) => Promise<TRes>,
7471
_functionName: string,

packages/meteor-lib/src/triggers/actionFactory.ts

Lines changed: 81 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ function createAdLibAction(
154154

155155
if (innerCtx) {
156156
try {
157-
return compiledAdLibFilter(innerCtx)
157+
return compiledAdLibFilter(innerCtx, true)
158158
} catch (e) {
159159
triggersContext.logger.error(e)
160160
return []
@@ -176,83 +176,83 @@ function createAdLibAction(
176176
const currentPartInstanceId = innerCtx.rundownPlaylist.get().currentPartInfo?.partInstanceId
177177

178178
const sourceLayerIdsToClear: string[] = []
179-
triggersContext
180-
.nonreactiveTracker(() => compiledAdLibFilter(innerCtx))
181-
.forEach((wrappedAdLib) => {
182-
switch (wrappedAdLib.type) {
183-
case MountedAdLibTriggerType.adLibPiece:
184-
triggersContext.doUserAction(t, e, UserAction.START_ADLIB, async (e, ts) =>
185-
currentPartInstanceId
186-
? triggersContext.MeteorCall.userAction.segmentAdLibPieceStart(
187-
e,
188-
ts,
189-
innerCtx.rundownPlaylistId.get(),
190-
currentPartInstanceId,
191-
wrappedAdLib.item._id,
192-
false
193-
)
194-
: ClientAPI.responseSuccess<void>(undefined)
195-
)
196-
break
197-
case MountedAdLibTriggerType.rundownBaselineAdLibItem:
198-
triggersContext.doUserAction(t, e, UserAction.START_GLOBAL_ADLIB, async (e, ts) =>
199-
currentPartInstanceId
200-
? triggersContext.MeteorCall.userAction.baselineAdLibPieceStart(
201-
e,
202-
ts,
203-
innerCtx.rundownPlaylistId.get(),
204-
currentPartInstanceId,
205-
wrappedAdLib.item._id,
206-
false
207-
)
208-
: ClientAPI.responseSuccess<void>(undefined)
209-
)
210-
break
211-
case MountedAdLibTriggerType.adLibAction:
212-
triggersContext.doUserAction(t, e, UserAction.START_ADLIB, async (e, ts) =>
213-
triggersContext.MeteorCall.userAction.executeAction(
214-
e,
215-
ts,
216-
innerCtx.rundownPlaylistId.get(),
217-
wrappedAdLib._id,
218-
wrappedAdLib.item.actionId,
219-
wrappedAdLib.item.userData,
220-
(actionArguments && actionArguments.triggerMode) || undefined
221-
)
179+
180+
const wrappedAdLibs = await compiledAdLibFilter(innerCtx, false)
181+
wrappedAdLibs.forEach((wrappedAdLib) => {
182+
switch (wrappedAdLib.type) {
183+
case MountedAdLibTriggerType.adLibPiece:
184+
triggersContext.doUserAction(t, e, UserAction.START_ADLIB, async (e, ts) =>
185+
currentPartInstanceId
186+
? triggersContext.MeteorCall.userAction.segmentAdLibPieceStart(
187+
e,
188+
ts,
189+
innerCtx.rundownPlaylistId.get(),
190+
currentPartInstanceId,
191+
wrappedAdLib.item._id,
192+
false
193+
)
194+
: ClientAPI.responseSuccess<void>(undefined)
195+
)
196+
break
197+
case MountedAdLibTriggerType.rundownBaselineAdLibItem:
198+
triggersContext.doUserAction(t, e, UserAction.START_GLOBAL_ADLIB, async (e, ts) =>
199+
currentPartInstanceId
200+
? triggersContext.MeteorCall.userAction.baselineAdLibPieceStart(
201+
e,
202+
ts,
203+
innerCtx.rundownPlaylistId.get(),
204+
currentPartInstanceId,
205+
wrappedAdLib.item._id,
206+
false
207+
)
208+
: ClientAPI.responseSuccess<void>(undefined)
209+
)
210+
break
211+
case MountedAdLibTriggerType.adLibAction:
212+
triggersContext.doUserAction(t, e, UserAction.START_ADLIB, async (e, ts) =>
213+
triggersContext.MeteorCall.userAction.executeAction(
214+
e,
215+
ts,
216+
innerCtx.rundownPlaylistId.get(),
217+
wrappedAdLib._id,
218+
wrappedAdLib.item.actionId,
219+
wrappedAdLib.item.userData,
220+
(actionArguments && actionArguments.triggerMode) || undefined
222221
)
223-
break
224-
case MountedAdLibTriggerType.rundownBaselineAdLibAction:
225-
triggersContext.doUserAction(t, e, UserAction.START_GLOBAL_ADLIB, async (e, ts) =>
226-
triggersContext.MeteorCall.userAction.executeAction(
227-
e,
228-
ts,
229-
innerCtx.rundownPlaylistId.get(),
230-
wrappedAdLib._id,
231-
wrappedAdLib.item.actionId,
232-
wrappedAdLib.item.userData,
233-
(actionArguments && actionArguments.triggerMode) || undefined
234-
)
222+
)
223+
break
224+
case MountedAdLibTriggerType.rundownBaselineAdLibAction:
225+
triggersContext.doUserAction(t, e, UserAction.START_GLOBAL_ADLIB, async (e, ts) =>
226+
triggersContext.MeteorCall.userAction.executeAction(
227+
e,
228+
ts,
229+
innerCtx.rundownPlaylistId.get(),
230+
wrappedAdLib._id,
231+
wrappedAdLib.item.actionId,
232+
wrappedAdLib.item.userData,
233+
(actionArguments && actionArguments.triggerMode) || undefined
235234
)
236-
break
237-
case MountedAdLibTriggerType.clearSourceLayer:
238-
// defer this action to send a single clear action all at once
239-
sourceLayerIdsToClear.push(wrappedAdLib.sourceLayerId)
240-
break
241-
case MountedAdLibTriggerType.sticky:
242-
triggersContext.doUserAction(t, e, UserAction.START_STICKY_PIECE, async (e, ts) =>
243-
triggersContext.MeteorCall.userAction.sourceLayerStickyPieceStart(
244-
e,
245-
ts,
246-
innerCtx.rundownPlaylistId.get(),
247-
wrappedAdLib.sourceLayerId //
248-
)
235+
)
236+
break
237+
case MountedAdLibTriggerType.clearSourceLayer:
238+
// defer this action to send a single clear action all at once
239+
sourceLayerIdsToClear.push(wrappedAdLib.sourceLayerId)
240+
break
241+
case MountedAdLibTriggerType.sticky:
242+
triggersContext.doUserAction(t, e, UserAction.START_STICKY_PIECE, async (e, ts) =>
243+
triggersContext.MeteorCall.userAction.sourceLayerStickyPieceStart(
244+
e,
245+
ts,
246+
innerCtx.rundownPlaylistId.get(),
247+
wrappedAdLib.sourceLayerId //
249248
)
250-
break
251-
default:
252-
assertNever(wrappedAdLib)
253-
return
254-
}
255-
})
249+
)
250+
break
251+
default:
252+
assertNever(wrappedAdLib)
253+
return
254+
}
255+
})
256256

257257
if (currentPartInstanceId && sourceLayerIdsToClear.length > 0) {
258258
triggersContext.doUserAction(t, e, UserAction.CLEAR_SOURCELAYER, async (e, ts) =>
@@ -411,12 +411,12 @@ function createUserActionWithCtx(
411411
return {
412412
action: action.action,
413413
execute: async (t, e, ctx) => {
414-
const innerCtx = await triggersContext.nonreactiveTracker(() =>
415-
createRundownPlaylistContext(triggersContext, ctx, action.filterChain)
416-
)
417-
if (innerCtx) {
418-
triggersContext.doUserAction(t, e, userAction, async (e, ts) => userActionExec(e, ts, innerCtx))
419-
}
414+
triggersContext.doUserAction(t, e, userAction, async (e, ts) => {
415+
const innerCtx = await createRundownPlaylistContext(triggersContext, ctx, action.filterChain)
416+
if (!innerCtx) return
417+
418+
return userActionExec(e, ts, innerCtx)
419+
})
420420
},
421421
}
422422
}

packages/meteor-lib/src/triggers/actionFilterChainCompilers.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -490,15 +490,16 @@ export function compileAdLibFilter(
490490
triggersContext: TriggersContext,
491491
filterChain: AdLibFilterChainLink[],
492492
sourceLayers: SourceLayers
493-
): (context: ReactivePlaylistActionContext) => Promise<IWrappedAdLib[]> {
493+
): (context: ReactivePlaylistActionContext, reactive: boolean) => Promise<IWrappedAdLib[]> {
494494
const onlyAdLibLinks = filterChain.filter((link) => link.object === 'adLib') as IAdLibFilterLink[]
495495
const adLibPieceTypeFilter = compileAdLibPieceFilter(onlyAdLibLinks, sourceLayers)
496496
const adLibActionTypeFilter = compileAdLibActionFilter(onlyAdLibLinks, sourceLayers)
497497

498498
const clearAdLibs = compileAndRunClearFilter(onlyAdLibLinks, sourceLayers)
499499
const stickyAdLibs = compileAndRunStickyFilter(onlyAdLibLinks, sourceLayers)
500500

501-
return async (context: ReactivePlaylistActionContext) => {
501+
// The contents of this method should be entirely non-reactive.
502+
return async (context: ReactivePlaylistActionContext, reactive: boolean) => {
502503
let rundownBaselineAdLibItems: IWrappedAdLib[] = []
503504
let adLibPieces: IWrappedAdLib[] = []
504505
let rundownBaselineAdLibActions: IWrappedAdLib[] = []
@@ -564,7 +565,7 @@ export function compileAdLibFilter(
564565
...currentNextOverride,
565566
rundownId: currentRundownId,
566567
} as MongoQuery<RundownBaselineAdLibItem>,
567-
{ ...adLibPieceTypeFilter.options, reactive: false }
568+
{ ...adLibPieceTypeFilter.options, reactive }
568569
)
569570
).map((item) => wrapAdLibPiece(item, MountedAdLibTriggerType.rundownBaselineAdLibItem))
570571
if (adLibPieceTypeFilter.global === undefined || adLibPieceTypeFilter.global === false)
@@ -575,7 +576,7 @@ export function compileAdLibFilter(
575576
...currentNextOverride,
576577
rundownId: currentRundownId,
577578
} as MongoQuery<AdLibPiece>,
578-
{ ...adLibPieceTypeFilter.options, reactive: false }
579+
{ ...adLibPieceTypeFilter.options, reactive }
579580
)
580581
).map((item) => wrapAdLibPiece(item, MountedAdLibTriggerType.adLibPiece))
581582
}
@@ -605,7 +606,7 @@ export function compileAdLibFilter(
605606
...currentNextOverride,
606607
rundownId: currentRundownId,
607608
} as MongoQuery<RundownBaselineAdLibAction>,
608-
{ ...adLibActionTypeFilter.options, reactive: false }
609+
{ ...adLibActionTypeFilter.options, reactive }
609610
)
610611
).map((item) =>
611612
wrapRundownBaselineAdLibAction(item, MountedAdLibTriggerType.rundownBaselineAdLibAction)
@@ -618,7 +619,7 @@ export function compileAdLibFilter(
618619
...currentNextOverride,
619620
rundownId: currentRundownId,
620621
} as MongoQuery<AdLibAction>,
621-
{ ...adLibActionTypeFilter.options, reactive: false }
622+
{ ...adLibActionTypeFilter.options, reactive }
622623
)
623624
).map((item) => wrapAdLibAction(item, MountedAdLibTriggerType.adLibAction))
624625
}

packages/meteor-lib/src/triggers/triggersContext.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,6 @@ export interface TriggersContext {
4444
_okMessage?: string
4545
): void
4646

47-
nonreactiveTracker<T>(func: () => T): T
48-
4947
memoizedIsolatedAutorun<TArgs extends any[], TRes>(
5048
fnc: (...args: TArgs) => Promise<TRes>,
5149
functionName: string,

packages/webui/src/client/lib/triggers/TriggersHandler.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,7 @@ export const TriggersHandler: React.FC<IProps> = function TriggersHandler(
457457
isolatedAutorunWithCleanup(() => {
458458
let previewAdLibs: IWrappedAdLib[] = []
459459
try {
460-
previewAdLibs = action.preview()
460+
previewAdLibs = await action.preview()
461461
} catch (e) {
462462
logger.error(e)
463463
}

packages/webui/src/client/lib/triggers/triggersContext.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,7 @@ export const UiTriggersContext: TriggersContext = {
3737

3838
hashSingleUseToken,
3939

40-
doUserAction,
41-
42-
nonreactiveTracker: Tracker.nonreactive,
40+
doUserAction: (...args) => Tracker.nonreactive(() => doUserAction(...args)),
4341

4442
memoizedIsolatedAutorun,
4543

0 commit comments

Comments
 (0)