Skip to content

Commit f681c79

Browse files
committed
Revert "wip: avoid nonreactive tracker"
This reverts commit b300e1f.
1 parent 5a35e49 commit f681c79

File tree

6 files changed

+96
-90
lines changed

6 files changed

+96
-90
lines changed

meteor/server/api/deviceTriggers/triggersContext.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ 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'
910

1011
import { logger } from '../../logging'
1112
import { IBaseFilterLink, IRundownPlaylistFilterLink } from '@sofie-automation/blueprints-integration'
@@ -66,6 +67,8 @@ export const MeteorTriggersContext: TriggersContext = {
6667
)
6768
},
6869

70+
nonreactiveTracker: Tracker.nonreactive,
71+
6972
memoizedIsolatedAutorun: async <TArgs extends any[], TRes>(
7073
fnc: (...args: TArgs) => Promise<TRes>,
7174
_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, true)
157+
return compiledAdLibFilter(innerCtx)
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-
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
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)
221195
)
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
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)
234209
)
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 //
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+
)
248222
)
249-
)
250-
break
251-
default:
252-
assertNever(wrappedAdLib)
253-
return
254-
}
255-
})
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+
)
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 //
248+
)
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-
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-
})
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+
}
420420
},
421421
}
422422
}

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

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -490,16 +490,15 @@ export function compileAdLibFilter(
490490
triggersContext: TriggersContext,
491491
filterChain: AdLibFilterChainLink[],
492492
sourceLayers: SourceLayers
493-
): (context: ReactivePlaylistActionContext, reactive: boolean) => Promise<IWrappedAdLib[]> {
493+
): (context: ReactivePlaylistActionContext) => 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-
// The contents of this method should be entirely non-reactive.
502-
return async (context: ReactivePlaylistActionContext, reactive: boolean) => {
501+
return async (context: ReactivePlaylistActionContext) => {
503502
let rundownBaselineAdLibItems: IWrappedAdLib[] = []
504503
let adLibPieces: IWrappedAdLib[] = []
505504
let rundownBaselineAdLibActions: IWrappedAdLib[] = []
@@ -565,7 +564,7 @@ export function compileAdLibFilter(
565564
...currentNextOverride,
566565
rundownId: currentRundownId,
567566
} as MongoQuery<RundownBaselineAdLibItem>,
568-
{ ...adLibPieceTypeFilter.options, reactive }
567+
{ ...adLibPieceTypeFilter.options, reactive: false }
569568
)
570569
).map((item) => wrapAdLibPiece(item, MountedAdLibTriggerType.rundownBaselineAdLibItem))
571570
if (adLibPieceTypeFilter.global === undefined || adLibPieceTypeFilter.global === false)
@@ -576,7 +575,7 @@ export function compileAdLibFilter(
576575
...currentNextOverride,
577576
rundownId: currentRundownId,
578577
} as MongoQuery<AdLibPiece>,
579-
{ ...adLibPieceTypeFilter.options, reactive }
578+
{ ...adLibPieceTypeFilter.options, reactive: false }
580579
)
581580
).map((item) => wrapAdLibPiece(item, MountedAdLibTriggerType.adLibPiece))
582581
}
@@ -606,7 +605,7 @@ export function compileAdLibFilter(
606605
...currentNextOverride,
607606
rundownId: currentRundownId,
608607
} as MongoQuery<RundownBaselineAdLibAction>,
609-
{ ...adLibActionTypeFilter.options, reactive }
608+
{ ...adLibActionTypeFilter.options, reactive: false }
610609
)
611610
).map((item) =>
612611
wrapRundownBaselineAdLibAction(item, MountedAdLibTriggerType.rundownBaselineAdLibAction)
@@ -619,7 +618,7 @@ export function compileAdLibFilter(
619618
...currentNextOverride,
620619
rundownId: currentRundownId,
621620
} as MongoQuery<AdLibAction>,
622-
{ ...adLibActionTypeFilter.options, reactive }
621+
{ ...adLibActionTypeFilter.options, reactive: false }
623622
)
624623
).map((item) => wrapAdLibAction(item, MountedAdLibTriggerType.adLibAction))
625624
}

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

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

47+
nonreactiveTracker<T>(func: () => T): T
48+
4749
memoizedIsolatedAutorun<TArgs extends any[], TRes>(
4850
fnc: (...args: TArgs) => Promise<TRes>,
4951
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 = await action.preview()
460+
previewAdLibs = action.preview()
461461
} catch (e) {
462462
logger.error(e)
463463
}

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

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

3838
hashSingleUseToken,
3939

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

4244
memoizedIsolatedAutorun,
4345

0 commit comments

Comments
 (0)