From defd5cfca5ceaa9ff360914912e0b451b9824777 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mi=C5=A1ko=20Hevery?= Date: Fri, 14 Jun 2024 18:39:21 -0400 Subject: [PATCH] WIP --- packages/qwik/src/core/v2/shared/scheduler.ts | 10 ++++++++++ packages/qwik/src/core/v2/signal/v2-signal.ts | 5 +++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/packages/qwik/src/core/v2/shared/scheduler.ts b/packages/qwik/src/core/v2/shared/scheduler.ts index 3c3648d564e..f22bf641438 100644 --- a/packages/qwik/src/core/v2/shared/scheduler.ts +++ b/packages/qwik/src/core/v2/shared/scheduler.ts @@ -99,6 +99,7 @@ import { vnode_documentPosition, vnode_isVNode } from '../client/vnode'; import { vnode_diff } from '../client/vnode-diff'; import { executeComponent2 } from './component-execution'; import type { Container2, HostElement, fixMeAny } from './types'; +import type { EffectSubscriptions } from '../signal/v2-signal'; // Turn this on to get debug output of what the scheduler is doing. const DEBUG: boolean = false; @@ -296,6 +297,15 @@ export const createScheduler = ( returnValue = runComputed2(chore.$payload$ as Task, container, host); break; case ChoreType.TASK: + const payload = chore.$payload$; + if (Array.isArray(payload)) { + // This is a hack to see if the scheduling will work. + const effectSubscriber = payload as fixMeAny as EffectSubscriptions; + const effect = effectSubscriber[0]; + returnValue = runSubscriber2(effect as Task, container, host); + break; + } + // eslint-disable-next-line no-fallthrough case ChoreType.VISIBLE: returnValue = runSubscriber2(chore.$payload$ as Task, container, host); break; diff --git a/packages/qwik/src/core/v2/signal/v2-signal.ts b/packages/qwik/src/core/v2/signal/v2-signal.ts index f9fcd7ec655..c5c92456903 100644 --- a/packages/qwik/src/core/v2/signal/v2-signal.ts +++ b/packages/qwik/src/core/v2/signal/v2-signal.ts @@ -22,6 +22,7 @@ import { isPromise } from '../../util/promises'; import { qDev } from '../../util/qdev'; import type { VNode } from '../client/types'; import { ChoreType, type Scheduler } from '../shared/scheduler'; +import type { fixMeAny } from '../shared/types'; import type { Signal2 as ISignal2 } from './v2-signal.public'; const DEBUG = true; @@ -102,7 +103,7 @@ type Effect = Task | VNode | Signal2; * effect can be scheduled if either `signalA` or `signalB` triggers. The `subscription1` is shared * between the signals. */ -type EffectSubscriptions = [Effect, InvokeContext | null, ...Signal2[]]; +export type EffectSubscriptions = [Effect, InvokeContext | null, ...Signal2[]]; class Signal2 implements ISignal2 { private $untrackedValue$: T; @@ -187,7 +188,7 @@ class Signal2 implements ISignal2 { DEBUG && log(' schedule.effect', String(effect)); if (isTask(effect)) { assertDefined(this.$scheduler$, 'Scheduler must be defined.'); - this.$scheduler$(ChoreType.TASK, effect); + this.$scheduler$(ChoreType.TASK, effectSubscriptions as fixMeAny); } else if (effect instanceof Signal2) { effect.$untrackedValue$ = NEEDS_COMPUTATION; effect.$effects$?.forEach(scheduleEffect);