Skip to content

Commit

Permalink
fix v2-signals tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Varixo committed Aug 9, 2024
1 parent f287219 commit 4289406
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 16 deletions.
20 changes: 4 additions & 16 deletions packages/qwik/src/core/use/use-task.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,8 @@ import { delay, isPromise, maybeThen, safeCall } from '../util/promises';
import { isFunction, isObject, type ValueOrPromise } from '../util/types';
import { ChoreType } from '../v2/shared/scheduler';
import { isContainer2, type Container2, type HostElement, type fixMeAny } from '../v2/shared/types';
import { EffectProperty } from '../v2/signal/v2-signal';
import {
createComputed2Qrl,
type ReadonlySignal2,
type Signal2,
} from '../v2/signal/v2-signal.public';
import { ComputedSignal2, EffectProperty, throwIfQRLNotResolved } from '../v2/signal/v2-signal';
import { type ReadonlySignal2, type Signal2 } from '../v2/signal/v2-signal.public';
import { invoke, newInvokeContext, untrack, waitAndRun } from './use-core';
import { useOn, useOnDocument } from './use-on';
import { useSequentialScope } from './use-sequential-scope';
Expand Down Expand Up @@ -435,18 +431,10 @@ export const useComputedQrl: ComputedQRL = <T>(qrl: QRL<ComputedFn<T>>): Signal2
return val;
}
assertQrl(qrl);
const signal = createComputed2Qrl(qrl);
const signal = new ComputedSignal2(null, qrl);
set(signal);

const resolved = qrl.resolved;
if (!resolved) {
// When we are creating a signal using a use method, we need to ensure
// that the computation can be lazy and therefore we need to unsure
// that the QRL is resolved.
// When we re-create the signal from serialization (we don't create the signal
// using useMethod) it is OK to not resolve it until the graph is marked as dirty.
throw qrl.resolve();
}
throwIfQRLNotResolved(qrl);
return signal;
};

Expand Down
13 changes: 13 additions & 0 deletions packages/qwik/src/core/v2/signal/v2-signal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,22 @@ export const createSignal2 = (value?: any) => {
};

export const createComputedSignal2 = <T>(qrl: QRL<() => T>) => {
throwIfQRLNotResolved(qrl);
return new ComputedSignal2(null, qrl as QRLInternal<() => T>);
};

export const throwIfQRLNotResolved = <T>(qrl: QRL<() => T>) => {
const resolved = qrl.resolved;
if (!resolved) {
// When we are creating a signal using a use method, we need to ensure
// that the computation can be lazy and therefore we need to unsure
// that the QRL is resolved.
// When we re-create the signal from serialization (we don't create the signal
// using useMethod) it is OK to not resolve it until the graph is marked as dirty.
throw qrl.resolve();
}
};

/** @public */
export const isSignal2 = (value: any): value is ISignal2<unknown> => {
return value instanceof Signal2;
Expand Down

0 comments on commit 4289406

Please sign in to comment.