Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
mhevery committed Jun 14, 2024
1 parent e23b4bf commit defd5cf
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
10 changes: 10 additions & 0 deletions packages/qwik/src/core/v2/shared/scheduler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -296,6 +297,15 @@ export const createScheduler = (
returnValue = runComputed2(chore.$payload$ as Task<TaskFn, TaskFn>, 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<TaskFn, TaskFn>, container, host);
break;
}
// eslint-disable-next-line no-fallthrough
case ChoreType.VISIBLE:
returnValue = runSubscriber2(chore.$payload$ as Task<TaskFn, TaskFn>, container, host);
break;
Expand Down
5 changes: 3 additions & 2 deletions packages/qwik/src/core/v2/signal/v2-signal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<T = any> implements ISignal2<T> {
private $untrackedValue$: T;
Expand Down Expand Up @@ -187,7 +188,7 @@ class Signal2<T = any> implements ISignal2<T> {
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);
Expand Down

0 comments on commit defd5cf

Please sign in to comment.