Skip to content

Commit

Permalink
rename DerivedSignal2 to WrappedSignal
Browse files Browse the repository at this point in the history
  • Loading branch information
Varixo committed Aug 31, 2024
1 parent 4fad01e commit 9b5e492
Show file tree
Hide file tree
Showing 9 changed files with 30 additions and 30 deletions.
6 changes: 3 additions & 3 deletions packages/qwik/src/core/debug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { isQrl } from '../server/prefetch-strategy';
import { isJSXNode } from './render/jsx/jsx-runtime';
import { isTask } from './use/use-task';
import { vnode_isVNode, vnode_toString } from './v2/client/vnode';
import { ComputedSignal2, DerivedSignal2, isSignal2 } from './v2/signal/v2-signal';
import { ComputedSignal2, WrappedSignal, isSignal2 } from './v2/signal/v2-signal';
import { isStore2 } from './v2/signal/v2-store';

const stringifyPath: any[] = [];
Expand Down Expand Up @@ -35,8 +35,8 @@ export function qwikDebugToString(value: any): any {
return value.map(qwikDebugToString);
}
} else if (isSignal2(value)) {
if (value instanceof DerivedSignal2) {
return 'DerivedSignal(' + qwikDebugToString(value.untrackedValue) + ')';
if (value instanceof WrappedSignal) {
return 'WrappedSignal(' + qwikDebugToString(value.untrackedValue) + ')';
} else if (value instanceof ComputedSignal2) {
return 'ComputedSignal(' + qwikDebugToString(value.untrackedValue) + ')';
} else {
Expand Down
4 changes: 2 additions & 2 deletions packages/qwik/src/core/qrl/inlined-fn.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { assertDefined } from '../error/assert';
import { SignalDerived } from '../state/signal';
import { qSerialize } from '../util/qdev';
import { DerivedSignal2 } from '../v2/signal/v2-signal';
import { WrappedSignal } from '../v2/signal/v2-signal';

/** @internal */
export const _fnSignal = <T extends (...args: any) => any>(
fn: T,
args: Parameters<T>,
fnStr?: string
) => {
return new DerivedSignal2(null, fn, args, fnStr || null);
return new WrappedSignal(null, fn, args, fnStr || null);
};

export const serializeDerivedSignalFunc = (signal: SignalDerived) => {
Expand Down
4 changes: 2 additions & 2 deletions packages/qwik/src/core/render/jsx/jsx-runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { ELEMENT_ID, OnRenderProp, QScopedStyle, QSlot, QSlotS } from '../../uti
import { isPromise } from '../../util/promises';
import { qDev, seal } from '../../util/qdev';
import { isArray, isObject, isString } from '../../util/types';
import { DerivedSignal2, isSignal2 } from '../../v2/signal/v2-signal';
import { WrappedSignal, isSignal2 } from '../../v2/signal/v2-signal';
import { static_subtree } from '../execute-component';
import type { DevJSX, FunctionComponent, JSXNode } from './types/jsx-node';
import type { QwikJSX } from './types/jsx-qwik';
Expand Down Expand Up @@ -388,7 +388,7 @@ class PropsProxyHandler implements ProxyHandler<any> {
? this.$constProps$[prop as string]
: this.$varProps$[prop as string];
// a proxied value that the optimizer made
return value instanceof DerivedSignal2 ? value.value : value;
return value instanceof WrappedSignal ? value.value : value;
}
set(_: any, prop: string | symbol, value: any) {
if (prop === _CONST_PROPS) {
Expand Down
8 changes: 4 additions & 4 deletions packages/qwik/src/core/state/signal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { logWarn } from '../util/log';
import { ComputedEvent, RenderEvent } from '../util/markers';
import { qDev, qSerialize } from '../util/qdev';
import { isObject } from '../util/types';
import { DerivedSignal2, isSignal2 } from '../v2/signal/v2-signal';
import { WrappedSignal, isSignal2 } from '../v2/signal/v2-signal';
import { getStoreTarget2 } from '../v2/signal/v2-store';
import {
LocalSubscriptionManager,
Expand Down Expand Up @@ -219,7 +219,7 @@ export const _wrapProp = <T extends Record<any, any>, P extends keyof T>(
}
if (isSignal2(obj)) {
assertEqual(prop, 'value', 'Left side is a signal, prop must be value');
return new DerivedSignal2(null, getProp, [obj, prop as string], null);
return new WrappedSignal(null, getProp, [obj, prop as string], null);
}
if (_CONST_PROPS in obj) {
const constProps = (obj as any)[_CONST_PROPS];
Expand All @@ -233,12 +233,12 @@ export const _wrapProp = <T extends Record<any, any>, P extends keyof T>(
const signal = target[prop];
const wrappedValue = isSignal2(signal)
? signal
: new DerivedSignal2(null, getProp, [obj, prop as string], null);
: new WrappedSignal(null, getProp, [obj, prop as string], null);
return wrappedValue;
}
}
// We need to forward the access to the original object
return new DerivedSignal2(null, getProp, [obj, prop as string], null);
return new WrappedSignal(null, getProp, [obj, prop as string], null);
};

/** @internal @deprecated v1 compat */
Expand Down
4 changes: 2 additions & 2 deletions packages/qwik/src/core/v2/client/vnode-diff.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ import {
type VNodeJournal,
} from './vnode';
import { getNewElementNamespaceData } from './vnode-namespace';
import { DerivedSignal2, EffectProperty, isSignal2 } from '../signal/v2-signal';
import { WrappedSignal, EffectProperty, isSignal2 } from '../signal/v2-signal';
import type { Signal2 } from '../signal/v2-signal.public';
import { executeComponent2 } from '../shared/component-execution';
import { isParentSlotProp, isSlotProp } from '../../util/prop';
Expand Down Expand Up @@ -513,7 +513,7 @@ export const vnode_diff = (
const constProps = jsxValue.constProps;
if (constProps && typeof constProps == 'object' && 'name' in constProps) {
const constValue = constProps.name;
if (constValue instanceof DerivedSignal2) {
if (constValue instanceof WrappedSignal) {
return trackSignal2(
() => constValue.value,
vHost as fixMeAny,
Expand Down
14 changes: 7 additions & 7 deletions packages/qwik/src/core/v2/shared/shared-serialization.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import { type DomContainer } from '../client/dom-container';
import { vnode_getNode, vnode_isVNode, vnode_locate } from '../client/vnode';
import {
ComputedSignal2,
DerivedSignal2,
WrappedSignal,
EffectSubscriptionsProp,
Signal2,
type EffectSubscriptions,
Expand Down Expand Up @@ -235,15 +235,15 @@ function upgradePropsWithDerivedSignal(
target: Record<string | symbol, any>,
property: string | symbol | number
): any {
const immutable: Record<string, DerivedSignal2<unknown>> = {};
const immutable: Record<string, WrappedSignal<unknown>> = {};
for (const key in target) {
if (Object.prototype.hasOwnProperty.call(target, key)) {
const value = target[key];
if (
typeof value === 'string' &&
value.charCodeAt(0) === SerializationConstant.DerivedSignal_VALUE
) {
const derivedSignal = (immutable[key] = allocate(value) as DerivedSignal2<unknown>);
const derivedSignal = (immutable[key] = allocate(value) as WrappedSignal<unknown>);
Object.defineProperty(target, key, {
get() {
return derivedSignal.value;
Expand Down Expand Up @@ -422,7 +422,7 @@ const allocate = <T>(value: string): any => {
case SerializationConstant.Signal_VALUE:
return new Signal2(null!, 0);
case SerializationConstant.DerivedSignal_VALUE:
return new DerivedSignal2(null!, null!, null!, null!);
return new WrappedSignal(null!, null!, null!, null!);
case SerializationConstant.ComputedSignal_VALUE:
return new ComputedSignal2(null!, null!);
case SerializationConstant.NotFinite_VALUE:
Expand Down Expand Up @@ -902,7 +902,7 @@ function serialize(serializationContext: SerializationContext): void {
}
serializeObjectLiteral(value, $writer$, writeValue, writeString);
} else if (value instanceof Signal2) {
if (value instanceof DerivedSignal2) {
if (value instanceof WrappedSignal) {
writeString(
SerializationConstant.DerivedSignal_CHAR +
serializeDerivedFn(serializationContext, value, $addRoot$) +
Expand Down Expand Up @@ -1084,7 +1084,7 @@ function serializeObjectProperties(

function serializeDerivedFn(
serializationContext: SerializationContext,
value: DerivedSignal2<any>,
value: WrappedSignal<any>,
$addRoot$: (obj: unknown) => number
) {
// if value is an object then we need to wrap this in ()
Expand All @@ -1111,7 +1111,7 @@ function deserializeSignal2(
const parts = data.substring(1).split(';');
let idx = 0;
if (readFn) {
const derivedSignal = signal as DerivedSignal2<any>;
const derivedSignal = signal as WrappedSignal<any>;
derivedSignal.$invalid$ = false;
const fnParts = parts[idx++].split(' ');
derivedSignal.$func$ = container.getSyncFn(parseInt(fnParts[0]));
Expand Down
12 changes: 6 additions & 6 deletions packages/qwik/src/core/v2/signal/v2-signal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ export const triggerEffects = (
const scheduleEffect = (effectSubscriptions: EffectSubscriptions) => {
const effect = effectSubscriptions[EffectSubscriptionsProp.EFFECT];
const property = effectSubscriptions[EffectSubscriptionsProp.PROPERTY];
assertDefined(container, 'Scheduler must be defined.');
assertDefined(container, 'Container must be defined.');
if (isTask(effect)) {
effect.$flags$ |= TaskFlags.DIRTY;
DEBUG && log('schedule.effect.task', pad('\n' + String(effect), ' '));
Expand All @@ -312,7 +312,7 @@ export const triggerEffects = (
container.$scheduler$(ChoreType.QRL_RESOLVE, null, effect.$computeQrl$);
}
}
(effect as ComputedSignal2<unknown> | DerivedSignal2<unknown>).$invalid$ = true;
(effect as ComputedSignal2<unknown> | WrappedSignal<unknown>).$invalid$ = true;
const previousSignal = signal;
try {
signal = effect;
Expand Down Expand Up @@ -445,9 +445,9 @@ export class ComputedSignal2<T> extends Signal2<T> {
throw new TypeError('ComputedSignal is read-only');
}
}
// TO DISCUSS (with Misko): Shouldn't it be called a "WrappedSignal" ?
// Plus - shouldn't this type of signal have the $dependencies$ array instead of EVERY type of signal?
export class DerivedSignal2<T> extends Signal2<T> {

// TO DISCUSS: shouldn't this type of signal have the $dependencies$ array instead of EVERY type of signal?
export class WrappedSignal<T> extends Signal2<T> {
$args$: any[];
$func$: (...args: any[]) => T;
$funcStr$: string | null;
Expand Down Expand Up @@ -518,6 +518,6 @@ export class DerivedSignal2<T> extends Signal2<T> {
}

set value(_: any) {
throw new TypeError('DerivedSignal is read-only');
throw new TypeError('WrappedSignal is read-only');
}
}
4 changes: 2 additions & 2 deletions packages/qwik/src/core/v2/ssr/ssr-render-jsx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import {
import { addComponentStylePrefix, hasClassAttr, isClassAttr } from '../shared/scoped-styles';
import { qrlToString, type SerializationContext } from '../shared/shared-serialization';
import { DEBUG_TYPE, VirtualType, type fixMeAny } from '../shared/types';
import { DerivedSignal2, EffectProperty, isSignal2 } from '../signal/v2-signal';
import { WrappedSignal, EffectProperty, isSignal2 } from '../signal/v2-signal';
import { applyInlineComponent, applyQwikComponentBody } from './ssr-render-component';
import type { ISsrNode, SSRContainer, SsrAttrs } from './ssr-types';
import { qInspector } from '../../util/qdev';
Expand Down Expand Up @@ -487,7 +487,7 @@ function getSlotName(host: ISsrNode, jsx: JSXNode, ssr: SSRContainer): string {
const constProps = jsx.constProps;
if (constProps && typeof constProps == 'object' && 'name' in constProps) {
const constValue = constProps.name;
if (constValue instanceof DerivedSignal2) {
if (constValue instanceof WrappedSignal) {
return trackSignal2(() => constValue.value, host as fixMeAny, EffectProperty.COMPONENT, ssr);
}
}
Expand Down
4 changes: 2 additions & 2 deletions packages/qwik/src/core/v2/tests/use-task.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
component$,
type Signal as SignalType,
} from '@builder.io/qwik';
import { DerivedSignal2 } from '../signal/v2-signal';
import { WrappedSignal } from '../signal/v2-signal';

const debug = false; //true;
Error.stackTraceLimit = 100;
Expand Down Expand Up @@ -183,7 +183,7 @@ describe.each([
it('should rerun on track derived signal', async () => {
const Counter = component$(() => {
const countRaw = useStore({ count: 10 });
const count = new DerivedSignal2(
const count = new WrappedSignal(
null,
(o: any, prop: string) => o[prop],
[countRaw, 'count'],
Expand Down

0 comments on commit 9b5e492

Please sign in to comment.