Skip to content

Commit c974009

Browse files
committed
chore: move store types to types file
1 parent 4f5207b commit c974009

File tree

10 files changed

+68
-51
lines changed

10 files changed

+68
-51
lines changed

packages/qwik/src/core/shared/scheduler.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ import { VNodeJournalOpCode, vnode_isVNode, vnode_setAttr } from '../client/vnod
9393
import { vnode_diff } from '../client/vnode-diff';
9494
import { triggerEffects } from '../signal/signal';
9595
import { isSignal, type Signal } from '../signal/signal.public';
96-
import type { TargetType } from '../signal/store';
96+
import type { StoreTarget } from '../signal/types';
9797
import type { ISsrNode } from '../ssr/ssr-types';
9898
import { runResource, type ResourceDescriptor } from '../use/use-resource';
9999
import {
@@ -140,7 +140,11 @@ export interface Chore {
140140

141141
export type Scheduler = ReturnType<typeof createScheduler>;
142142

143-
type ChoreTarget = HostElement | QRLInternal<(...args: unknown[]) => unknown> | Signal | TargetType;
143+
type ChoreTarget =
144+
| HostElement
145+
| QRLInternal<(...args: unknown[]) => unknown>
146+
| Signal
147+
| StoreTarget;
144148

145149
const getPromise = (chore: Chore) =>
146150
(chore.$promise$ ||= new Promise((resolve) => {

packages/qwik/src/core/shared/shared-serialization.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,7 @@ import { vnode_getNode, vnode_isVNode, vnode_locate, vnode_toString } from '../c
1010
import { _EFFECT_BACK_REF, NEEDS_COMPUTATION } from '../signal/flags';
1111
import { isSerializerObj } from '../signal/signal';
1212
import type { SerializerArg } from '../signal/types';
13-
import {
14-
getOrCreateStore,
15-
getStoreHandler,
16-
getStoreTarget,
17-
isStore,
18-
STORE_ALL_PROPS,
19-
} from '../signal/store';
13+
import { getOrCreateStore, getStoreHandler, getStoreTarget, isStore } from '../signal/store';
2014
import type { ISsrNode, SsrAttrs, SymbolToChunkResolver } from '../ssr/ssr-types';
2115
import { untrack } from '../use/use-core';
2216
import { createResourceReturn, type ResourceReturnInternal } from '../use/use-resource';
@@ -48,6 +42,7 @@ import { type ValueOrPromise } from './utils/types';
4842
import {
4943
EffectSubscriptionProp,
5044
SignalFlags,
45+
STORE_ALL_PROPS,
5146
type AllSignalFlags,
5247
type EffectProperty,
5348
type EffectSubscription,

packages/qwik/src/core/shared/shared-serialization.unit.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
createSignal,
99
isSignal,
1010
} from '../signal/signal.public';
11-
import { StoreFlags, createStore } from '../signal/store';
11+
import { createStore } from '../signal/store';
1212
import { createResourceReturn } from '../use/use-resource';
1313
import { Task } from '../use/use-task';
1414
import { inlinedQrl } from './qrl/qrl';
@@ -25,6 +25,7 @@ import { EMPTY_ARRAY, EMPTY_OBJ } from './utils/flyweight';
2525
import { isQrl } from './qrl/qrl-utils';
2626
import { NoSerializeSymbol, SerializerSymbol } from './utils/serialize-utils';
2727
import { SubscriptionData } from '../signal/subscription-data';
28+
import { StoreFlags } from '../signal/types';
2829

2930
const DEBUG = false;
3031

packages/qwik/src/core/signal/signal.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@ import { ComputedSignalImpl } from './impl/computed-signal-impl';
1616
import { SignalImpl } from './impl/signal-impl';
1717
import type { WrappedSignalImpl } from './impl/wrapped-signal-impl';
1818
import type { Signal } from './signal.public';
19-
import type { TargetType } from './store';
2019
import { SubscriptionData, type NodePropPayload } from './subscription-data';
2120
import {
2221
EffectProperty,
2322
EffectSubscriptionProp,
2423
type CustomSerializable,
2524
type EffectSubscription,
25+
type StoreTarget,
2626
} from './types';
2727

2828
const DEBUG = false;
@@ -83,7 +83,7 @@ export const addQrlToSerializationCtx = (
8383

8484
export const triggerEffects = (
8585
container: Container | null,
86-
signal: SignalImpl | TargetType,
86+
signal: SignalImpl | StoreTarget,
8787
effects: Set<EffectSubscription> | null
8888
) => {
8989
const isBrowser = isDomContainer(container);

packages/qwik/src/core/signal/store.ts

Lines changed: 19 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -9,30 +9,25 @@ import {
99
ensureContainsSubscription,
1010
triggerEffects,
1111
} from './signal';
12-
import type { EffectSubscription } from './types';
12+
import {
13+
STORE_ALL_PROPS,
14+
STORE_HANDLER,
15+
STORE_TARGET,
16+
StoreFlags,
17+
type EffectSubscription,
18+
type StoreTarget,
19+
} from './types';
1320

1421
const DEBUG = false;
1522

1623
// eslint-disable-next-line no-console
1724
const log = (...args: any[]) => console.log('STORE', ...args.map(qwikDebugToString));
1825

19-
const STORE_TARGET = Symbol('store.target');
20-
const STORE_HANDLER = Symbol('store.handler');
21-
export const STORE_ALL_PROPS = Symbol('store.all');
22-
23-
export type TargetType = Record<string | symbol, any>;
24-
25-
export const enum StoreFlags {
26-
NONE = 0,
27-
RECURSIVE = 1,
28-
IMMUTABLE = 2,
29-
}
30-
31-
export const getStoreHandler = (value: TargetType): StoreHandler | null => {
26+
export const getStoreHandler = (value: StoreTarget): StoreHandler | null => {
3227
return value[STORE_HANDLER] as StoreHandler | null;
3328
};
3429

35-
export const getStoreTarget = <T extends TargetType>(value: T): T | null => {
30+
export const getStoreTarget = <T extends StoreTarget>(value: T): T | null => {
3631
return value?.[STORE_TARGET] || null;
3732
};
3833

@@ -46,7 +41,7 @@ export const unwrapStore = <T>(value: T): T => {
4641
return getStoreTarget<any>(value) || value;
4742
};
4843

49-
export const isStore = (value: TargetType): boolean => {
44+
export const isStore = (value: StoreTarget): boolean => {
5045
return STORE_TARGET in value;
5146
};
5247

@@ -74,7 +69,7 @@ export const getOrCreateStore = <T extends object>(
7469
return obj;
7570
};
7671

77-
export class StoreHandler implements ProxyHandler<TargetType> {
72+
export class StoreHandler implements ProxyHandler<StoreTarget> {
7873
$effects$: null | Map<string | symbol, Set<EffectSubscription>> = null;
7974

8075
constructor(
@@ -86,7 +81,7 @@ export class StoreHandler implements ProxyHandler<TargetType> {
8681
return '[Store]';
8782
}
8883

89-
get(target: TargetType, prop: string | symbol) {
84+
get(target: StoreTarget, prop: string | symbol) {
9085
if (typeof prop === 'symbol') {
9186
if (prop === STORE_TARGET) {
9287
return target;
@@ -141,7 +136,7 @@ export class StoreHandler implements ProxyHandler<TargetType> {
141136
}
142137

143138
/** In the case of oldValue and value are the same, the effects are not triggered. */
144-
set(target: TargetType, prop: string | symbol, value: any): boolean {
139+
set(target: StoreTarget, prop: string | symbol, value: any): boolean {
145140
if (typeof prop === 'symbol') {
146141
target[prop] = value;
147142
return true;
@@ -161,15 +156,15 @@ export class StoreHandler implements ProxyHandler<TargetType> {
161156
return true;
162157
}
163158

164-
deleteProperty(target: TargetType, prop: string | symbol): boolean {
159+
deleteProperty(target: StoreTarget, prop: string | symbol): boolean {
165160
if (typeof prop != 'string' || !delete target[prop]) {
166161
return false;
167162
}
168163
triggerEffects(this.$container$, this, getEffects(target, prop, this.$effects$));
169164
return true;
170165
}
171166

172-
has(target: TargetType, prop: string | symbol) {
167+
has(target: StoreTarget, prop: string | symbol) {
173168
if (prop === STORE_TARGET) {
174169
return true;
175170
}
@@ -190,7 +185,7 @@ export class StoreHandler implements ProxyHandler<TargetType> {
190185
return Object.prototype.hasOwnProperty.call(target, prop);
191186
}
192187

193-
ownKeys(target: TargetType): ArrayLike<string | symbol> {
188+
ownKeys(target: StoreTarget): ArrayLike<string | symbol> {
194189
const ctx = tryGetInvokeContext();
195190
const effectSubscriber = ctx?.$effectSubscriber$;
196191
if (effectSubscriber) {
@@ -200,7 +195,7 @@ export class StoreHandler implements ProxyHandler<TargetType> {
200195
}
201196

202197
getOwnPropertyDescriptor(
203-
target: TargetType,
198+
target: StoreTarget,
204199
prop: string | symbol
205200
): PropertyDescriptor | undefined {
206201
const descriptor = Reflect.getOwnPropertyDescriptor(target, prop);
@@ -218,7 +213,7 @@ export class StoreHandler implements ProxyHandler<TargetType> {
218213
}
219214

220215
export function addStoreEffect(
221-
target: TargetType,
216+
target: StoreTarget,
222217
prop: string | symbol,
223218
store: StoreHandler,
224219
effectSubscription: EffectSubscription

packages/qwik/src/core/signal/store.unit.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ import { getDomContainer, implicit$FirstArg, type QRL } from '@qwik.dev/core';
22
import { createDocument, getTestPlatform } from '@qwik.dev/core/testing';
33
import { afterEach, beforeEach, describe, expect, it } from 'vitest';
44
import type { Container, HostElement } from '../shared/types';
5-
import { StoreFlags, getOrCreateStore, isStore } from './store';
6-
import { EffectProperty } from './types';
5+
import { getOrCreateStore, isStore } from './store';
6+
import { EffectProperty, StoreFlags } from './types';
77
import { invoke } from '../use/use-core';
88
import { newInvokeContext } from '../use/use-core';
99
import { ChoreType } from '../shared/util-chore-type';

packages/qwik/src/core/signal/types.ts

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,18 @@ import type { ISsrNode } from '../ssr/ssr-types';
33
import type { Task } from '../use/use-task';
44
import type { SubscriptionData } from './subscription-data';
55
import type { ReadonlySignal } from './signal.public';
6-
import type { TargetType } from './store';
76
import type { SignalImpl } from './impl/signal-impl';
87
import type { QRLInternal } from '../shared/qrl/qrl-class';
98
import type { SerializerSymbol } from '../shared/utils/serialize-utils';
109

10+
/**
11+
* # ================================
12+
*
13+
* Signal Types
14+
*
15+
* # ================================
16+
*/
17+
1118
export interface InternalReadonlySignal<T = unknown> extends ReadonlySignal<T> {
1219
readonly untrackedValue: T;
1320
}
@@ -80,7 +87,7 @@ export type Consumer = Task | VNode | ISsrNode | SignalImpl;
8087
export type EffectSubscription = [
8188
Consumer, // EffectSubscriptionProp.CONSUMER
8289
EffectProperty | string, // EffectSubscriptionProp.PROPERTY or string for attributes
83-
Set<SignalImpl | TargetType> | null, // EffectSubscriptionProp.BACK_REF
90+
Set<SignalImpl | StoreTarget> | null, // EffectSubscriptionProp.BACK_REF
8491
SubscriptionData | null, // EffectSubscriptionProp.DATA
8592
];
8693

@@ -145,3 +152,23 @@ export type SerializerArg<T, S> =
145152
export type CustomSerializable<T extends { [SerializerSymbol]: (obj: any) => any }, S> = {
146153
[SerializerSymbol]: (obj: T) => S;
147154
};
155+
156+
/**
157+
* # ================================
158+
*
159+
* Store Types
160+
*
161+
* # ================================
162+
*/
163+
164+
export const STORE_TARGET = Symbol('store.target');
165+
export const STORE_HANDLER = Symbol('store.handler');
166+
export const STORE_ALL_PROPS = Symbol('store.all');
167+
168+
export type StoreTarget = Record<string | symbol, any>;
169+
170+
export const enum StoreFlags {
171+
NONE = 0,
172+
RECURSIVE = 1,
173+
IMMUTABLE = 2,
174+
}

packages/qwik/src/core/use/use-resource.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import type { Container, HostElement, ValueOrPromise } from '../../server/qwik-t
99
import type { JSXOutput } from '../shared/jsx/types/jsx-node';
1010
import { delay, isPromise, safeCall } from '../shared/utils/promises';
1111
import { isFunction, isObject } from '../shared/utils/types';
12-
import { StoreFlags, createStore, getStoreTarget, unwrapStore } from '../signal/store';
12+
import { createStore, getStoreTarget, unwrapStore } from '../signal/store';
1313
import { useSequentialScope } from './use-sequential-scope';
1414
import { isSignal } from '../signal/signal';
1515
import type { Signal } from '../signal/signal.public';
@@ -19,7 +19,7 @@ import { assertDefined } from '../shared/error/assert';
1919
import { noSerialize } from '../shared/utils/serialize-utils';
2020
import { ChoreType } from '../shared/util-chore-type';
2121
import { getSubscriber } from '../signal/subscriber';
22-
import { EffectProperty } from '../signal/types';
22+
import { EffectProperty, StoreFlags } from '../signal/types';
2323

2424
const DEBUG: boolean = false;
2525

packages/qwik/src/core/use/use-store.public.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { isFunction } from '../shared/utils/types';
2-
import { StoreFlags, getOrCreateStore } from '../signal/store';
2+
import { getOrCreateStore } from '../signal/store';
3+
import { StoreFlags } from '../signal/types';
34
import { invoke } from './use-core';
45
import { useSequentialScope } from './use-sequential-scope';
56

packages/qwik/src/core/use/use-task.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,8 @@ import { useLexicalScope } from './use-lexical-scope.public';
1818
import type { ResourceReturnInternal } from './use-resource';
1919
import { useSequentialScope } from './use-sequential-scope';
2020
import { getSubscriber } from '../signal/subscriber';
21-
import {
22-
STORE_ALL_PROPS,
23-
addStoreEffect,
24-
getStoreHandler,
25-
getStoreTarget,
26-
isStore,
27-
} from '../signal/store';
28-
import { EffectProperty } from '../signal/types';
21+
import { addStoreEffect, getStoreHandler, getStoreTarget, isStore } from '../signal/store';
22+
import { EffectProperty, STORE_ALL_PROPS } from '../signal/types';
2923

3024
export const enum TaskFlags {
3125
VISIBLE_TASK = 1 << 0,

0 commit comments

Comments
 (0)