From 9b5e49293fed4dd1c8dc2d6bb8c733fa39f322ba Mon Sep 17 00:00:00 2001 From: Varixo Date: Sat, 31 Aug 2024 18:56:46 +0200 Subject: [PATCH] rename DerivedSignal2 to WrappedSignal --- packages/qwik/src/core/debug.ts | 6 +++--- packages/qwik/src/core/qrl/inlined-fn.ts | 4 ++-- packages/qwik/src/core/render/jsx/jsx-runtime.ts | 4 ++-- packages/qwik/src/core/state/signal.ts | 8 ++++---- packages/qwik/src/core/v2/client/vnode-diff.ts | 4 ++-- .../src/core/v2/shared/shared-serialization.ts | 14 +++++++------- packages/qwik/src/core/v2/signal/v2-signal.ts | 12 ++++++------ packages/qwik/src/core/v2/ssr/ssr-render-jsx.ts | 4 ++-- packages/qwik/src/core/v2/tests/use-task.spec.tsx | 4 ++-- 9 files changed, 30 insertions(+), 30 deletions(-) diff --git a/packages/qwik/src/core/debug.ts b/packages/qwik/src/core/debug.ts index 63aa140dfc0..a568aa09ffe 100644 --- a/packages/qwik/src/core/debug.ts +++ b/packages/qwik/src/core/debug.ts @@ -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[] = []; @@ -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 { diff --git a/packages/qwik/src/core/qrl/inlined-fn.ts b/packages/qwik/src/core/qrl/inlined-fn.ts index d5e51aef67a..159385d7fdc 100644 --- a/packages/qwik/src/core/qrl/inlined-fn.ts +++ b/packages/qwik/src/core/qrl/inlined-fn.ts @@ -1,7 +1,7 @@ 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 = any>( @@ -9,7 +9,7 @@ export const _fnSignal = any>( args: Parameters, fnStr?: string ) => { - return new DerivedSignal2(null, fn, args, fnStr || null); + return new WrappedSignal(null, fn, args, fnStr || null); }; export const serializeDerivedSignalFunc = (signal: SignalDerived) => { diff --git a/packages/qwik/src/core/render/jsx/jsx-runtime.ts b/packages/qwik/src/core/render/jsx/jsx-runtime.ts index b1a2b9e40c4..88bf751d1cf 100644 --- a/packages/qwik/src/core/render/jsx/jsx-runtime.ts +++ b/packages/qwik/src/core/render/jsx/jsx-runtime.ts @@ -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'; @@ -388,7 +388,7 @@ class PropsProxyHandler implements ProxyHandler { ? 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) { diff --git a/packages/qwik/src/core/state/signal.ts b/packages/qwik/src/core/state/signal.ts index bb94150d68c..110cc36f6cd 100644 --- a/packages/qwik/src/core/state/signal.ts +++ b/packages/qwik/src/core/state/signal.ts @@ -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, @@ -219,7 +219,7 @@ export const _wrapProp = , 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]; @@ -233,12 +233,12 @@ export const _wrapProp = , 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 */ diff --git a/packages/qwik/src/core/v2/client/vnode-diff.ts b/packages/qwik/src/core/v2/client/vnode-diff.ts index 2a6b35d815f..d49b5710190 100644 --- a/packages/qwik/src/core/v2/client/vnode-diff.ts +++ b/packages/qwik/src/core/v2/client/vnode-diff.ts @@ -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'; @@ -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, diff --git a/packages/qwik/src/core/v2/shared/shared-serialization.ts b/packages/qwik/src/core/v2/shared/shared-serialization.ts index 4770fc2cd2e..51c440ab364 100644 --- a/packages/qwik/src/core/v2/shared/shared-serialization.ts +++ b/packages/qwik/src/core/v2/shared/shared-serialization.ts @@ -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, @@ -235,7 +235,7 @@ function upgradePropsWithDerivedSignal( target: Record, property: string | symbol | number ): any { - const immutable: Record> = {}; + const immutable: Record> = {}; for (const key in target) { if (Object.prototype.hasOwnProperty.call(target, key)) { const value = target[key]; @@ -243,7 +243,7 @@ function upgradePropsWithDerivedSignal( typeof value === 'string' && value.charCodeAt(0) === SerializationConstant.DerivedSignal_VALUE ) { - const derivedSignal = (immutable[key] = allocate(value) as DerivedSignal2); + const derivedSignal = (immutable[key] = allocate(value) as WrappedSignal); Object.defineProperty(target, key, { get() { return derivedSignal.value; @@ -422,7 +422,7 @@ const allocate = (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: @@ -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$) + @@ -1084,7 +1084,7 @@ function serializeObjectProperties( function serializeDerivedFn( serializationContext: SerializationContext, - value: DerivedSignal2, + value: WrappedSignal, $addRoot$: (obj: unknown) => number ) { // if value is an object then we need to wrap this in () @@ -1111,7 +1111,7 @@ function deserializeSignal2( const parts = data.substring(1).split(';'); let idx = 0; if (readFn) { - const derivedSignal = signal as DerivedSignal2; + const derivedSignal = signal as WrappedSignal; derivedSignal.$invalid$ = false; const fnParts = parts[idx++].split(' '); derivedSignal.$func$ = container.getSyncFn(parseInt(fnParts[0])); diff --git a/packages/qwik/src/core/v2/signal/v2-signal.ts b/packages/qwik/src/core/v2/signal/v2-signal.ts index 73471216fee..7609c868ffb 100644 --- a/packages/qwik/src/core/v2/signal/v2-signal.ts +++ b/packages/qwik/src/core/v2/signal/v2-signal.ts @@ -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), ' ')); @@ -312,7 +312,7 @@ export const triggerEffects = ( container.$scheduler$(ChoreType.QRL_RESOLVE, null, effect.$computeQrl$); } } - (effect as ComputedSignal2 | DerivedSignal2).$invalid$ = true; + (effect as ComputedSignal2 | WrappedSignal).$invalid$ = true; const previousSignal = signal; try { signal = effect; @@ -445,9 +445,9 @@ export class ComputedSignal2 extends Signal2 { 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 extends Signal2 { + +// TO DISCUSS: shouldn't this type of signal have the $dependencies$ array instead of EVERY type of signal? +export class WrappedSignal extends Signal2 { $args$: any[]; $func$: (...args: any[]) => T; $funcStr$: string | null; @@ -518,6 +518,6 @@ export class DerivedSignal2 extends Signal2 { } set value(_: any) { - throw new TypeError('DerivedSignal is read-only'); + throw new TypeError('WrappedSignal is read-only'); } } diff --git a/packages/qwik/src/core/v2/ssr/ssr-render-jsx.ts b/packages/qwik/src/core/v2/ssr/ssr-render-jsx.ts index 6a5c38e5798..ab07b604797 100644 --- a/packages/qwik/src/core/v2/ssr/ssr-render-jsx.ts +++ b/packages/qwik/src/core/v2/ssr/ssr-render-jsx.ts @@ -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'; @@ -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); } } diff --git a/packages/qwik/src/core/v2/tests/use-task.spec.tsx b/packages/qwik/src/core/v2/tests/use-task.spec.tsx index 17d23924140..04fc40b5038 100644 --- a/packages/qwik/src/core/v2/tests/use-task.spec.tsx +++ b/packages/qwik/src/core/v2/tests/use-task.spec.tsx @@ -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; @@ -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'],