Skip to content

Commit 706e50a

Browse files
committed
wip: this probably doesn't work, need to figure out how to do reactivity correctly..
1 parent b300e1f commit 706e50a

File tree

4 files changed

+67
-53
lines changed

4 files changed

+67
-53
lines changed

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

Lines changed: 59 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -634,30 +634,34 @@ export function compileAdLibFilter(
634634
// because _.isEqual (used in memoizedIsolatedAutorun) doesn't work with Maps..
635635

636636
const rundownPlaylistId = context.rundownPlaylistId.get()
637-
const rundownRanks = await triggersContext.memoizedIsolatedAutorun(async () => {
638-
const playlist = (await triggersContext.RundownPlaylists.findOneAsync(rundownPlaylistId, {
639-
projection: {
640-
rundownIdsInOrder: 1,
641-
},
642-
})) as Pick<DBRundownPlaylist, 'rundownIdsInOrder'> | undefined
643-
644-
if (playlist?.rundownIdsInOrder) {
645-
return playlist.rundownIdsInOrder
646-
} else {
647-
const rundowns = (await triggersContext.Rundowns.findFetchAsync(
648-
{
649-
playlistId: rundownPlaylistId,
637+
const rundownRanks = await triggersContext.memoizedIsolatedAutorun(
638+
async () => {
639+
const playlist = (await triggersContext.RundownPlaylists.findOneAsync(rundownPlaylistId, {
640+
projection: {
641+
rundownIdsInOrder: 1,
650642
},
651-
{
652-
fields: {
653-
_id: 1,
643+
})) as Pick<DBRundownPlaylist, 'rundownIdsInOrder'> | undefined
644+
645+
if (playlist?.rundownIdsInOrder) {
646+
return playlist.rundownIdsInOrder
647+
} else {
648+
const rundowns = (await triggersContext.Rundowns.findFetchAsync(
649+
{
650+
playlistId: rundownPlaylistId,
654651
},
655-
}
656-
)) as Pick<DBRundown, '_id'>[]
657-
658-
return rundowns.map((r) => r._id)
659-
}
660-
}, `rundownsRanksForPlaylist_${rundownPlaylistId}`)
652+
{
653+
fields: {
654+
_id: 1,
655+
},
656+
}
657+
)) as Pick<DBRundown, '_id'>[]
658+
659+
return rundowns.map((r) => r._id)
660+
}
661+
},
662+
reactive,
663+
`rundownsRanksForPlaylist_${rundownPlaylistId}`
664+
)
661665
rundownRanks.forEach((id, index) => {
662666
rundownRankMap.set(id, index)
663667
})
@@ -675,41 +679,46 @@ export function compileAdLibFilter(
675679
},
676680
}
677681
)) as Pick<DBSegment, '_id' | '_rank'>[],
682+
reactive,
678683
`segmentRanksForRundowns_${Array.from(rundownRankMap.keys()).join(',')}`
679684
)
680685
segmentRanks.forEach((segment) => {
681686
segmentRankMap.set(segment._id, segment._rank)
682687
})
683688

684-
const partRanks = await triggersContext.memoizedIsolatedAutorun(async () => {
685-
if (!partFilter) {
686-
return (await triggersContext.Parts.findFetchAsync(
687-
{
688-
rundownId: { $in: Array.from(rundownRankMap.keys()) },
689-
},
690-
{
691-
fields: {
692-
_id: 1,
693-
segmentId: 1,
694-
rundownId: 1,
695-
_rank: 1,
696-
},
697-
}
698-
)) as Pick<DBPart, '_id' | '_rank' | 'segmentId' | 'rundownId'>[]
699-
} else {
700-
return (await triggersContext.Parts.findFetchAsync(
701-
{ _id: { $in: partFilter } },
702-
{
703-
fields: {
704-
_id: 1,
705-
segmentId: 1,
706-
rundownId: 1,
707-
_rank: 1,
689+
const partRanks = await triggersContext.memoizedIsolatedAutorun(
690+
async () => {
691+
if (!partFilter) {
692+
return (await triggersContext.Parts.findFetchAsync(
693+
{
694+
rundownId: { $in: Array.from(rundownRankMap.keys()) },
708695
},
709-
}
710-
)) as Pick<DBPart, '_id' | '_rank' | 'segmentId' | 'rundownId'>[]
711-
}
712-
}, `partRanks_${JSON.stringify(partFilter ?? rundownRankMap.keys())}`)
696+
{
697+
fields: {
698+
_id: 1,
699+
segmentId: 1,
700+
rundownId: 1,
701+
_rank: 1,
702+
},
703+
}
704+
)) as Pick<DBPart, '_id' | '_rank' | 'segmentId' | 'rundownId'>[]
705+
} else {
706+
return (await triggersContext.Parts.findFetchAsync(
707+
{ _id: { $in: partFilter } },
708+
{
709+
fields: {
710+
_id: 1,
711+
segmentId: 1,
712+
rundownId: 1,
713+
_rank: 1,
714+
},
715+
}
716+
)) as Pick<DBPart, '_id' | '_rank' | 'segmentId' | 'rundownId'>[]
717+
}
718+
},
719+
reactive,
720+
`partRanks_${JSON.stringify(partFilter ?? rundownRankMap.keys())}`
721+
)
713722

714723
partRanks.forEach((part) => {
715724
partRankMap.set(part._id, part)

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ export interface TriggersContext {
4646

4747
memoizedIsolatedAutorun<TArgs extends any[], TRes>(
4848
fnc: (...args: TArgs) => Promise<TRes>,
49+
reactive: boolean,
4950
functionName: string,
5051
...params: TArgs
5152
): Promise<TRes>

packages/webui/src/client/lib/memoizedIsolatedAutorun.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@ const isolatedAutorunsMem: {
1919
* If the `fnc` computation is invalidated, the outer computations will only be invalidated if the value returned from
2020
* `fnc` fails a deep equality check (_.isEqual).
2121
*
22-
* If used in server code, thie `fnc` will be run as-is, without any reactivity
23-
*
2422
* @export
2523
* @template T
2624
* @param {T} fnc The computation function to be memoized and calculated separately from the outer one.

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,13 @@ export const UiTriggersContext: TriggersContext = {
3939

4040
doUserAction: (...args) => Tracker.nonreactive(() => doUserAction(...args)),
4141

42-
memoizedIsolatedAutorun,
42+
memoizedIsolatedAutorun: async (fnc, reactive, functionName, ...params) => {
43+
if (!reactive) {
44+
return Tracker.nonreactive(() => memoizedIsolatedAutorun(fnc, functionName, ...params))
45+
} else {
46+
return memoizedIsolatedAutorun(fnc, functionName, ...params)
47+
}
48+
},
4349

4450
async createContextForRundownPlaylistChain(
4551
_studioId: StudioId,

0 commit comments

Comments
 (0)