Skip to content

Commit 0408795

Browse files
committed
WIP: remove $ from shared variables
1 parent a5e7818 commit 0408795

File tree

12 files changed

+49
-42
lines changed

12 files changed

+49
-42
lines changed

packages/qwik/src/core/client/dom-container.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@ export class DomContainer extends _SharedContainer implements IClientContainer {
372372
containerAttributes[attr.name] = attr.value;
373373
}
374374
}
375-
this.$serverData$ = { containerAttributes };
375+
this.serverData = { containerAttributes };
376376
}
377377

378378
/**

packages/qwik/src/core/client/dom-render.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ export const render = async (
4040
(parent as Element).setAttribute(QContainerAttr, QContainerValue.RESUMED);
4141

4242
const container = getDomContainer(parent as HTMLElement) as DomContainer;
43-
container.$serverData$ = opts.serverData || {};
43+
container.serverData = opts.serverData || {};
4444
const host = container.rootVNode;
4545
container.$scheduler$(ChoreType.NODE_DIFF, host, host, jsxNode as JSXNode);
4646
await container.$scheduler$(ChoreType.WAIT_FOR_ALL);

packages/qwik/src/core/qwik.core.api.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -870,8 +870,6 @@ export abstract class _SharedContainer implements Container {
870870
// (undocumented)
871871
readonly $scheduler$: Scheduler;
872872
// (undocumented)
873-
$serverData$: Record<string, any>;
874-
// (undocumented)
875873
readonly $storeProxyMap$: ObjToProxyMap;
876874
// (undocumented)
877875
readonly $version$: string;
@@ -901,6 +899,8 @@ export abstract class _SharedContainer implements Container {
901899
};
902900
} | null, symbolToChunkResolver: SymbolToChunkResolver, writer?: StreamWriter, prepVNodeData?: (vNode: any) => void): SerializationContext;
903901
// (undocumented)
902+
serverData: Record<string, any>;
903+
// (undocumented)
904904
abstract setContext<T>(host: HostElement, context: ContextId<T>, value: T): void;
905905
// (undocumented)
906906
abstract setHostProp<T>(host: HostElement, name: string, value: T): void;

packages/qwik/src/core/reactive-primitives/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ export const addQrlToSerializationCtx = (
7575
qrl = container.getHostProp<QRL>(effect as ISsrNode, OnRenderProp);
7676
}
7777
if (qrl) {
78-
(container as SSRContainer).serializationCtx.$eventQrls$.add(qrl);
78+
(container as SSRContainer).serializationCtx.eventQrls.add(qrl);
7979
}
8080
}
8181
};

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export abstract class _SharedContainer implements Container {
1818
readonly $locale$: string;
1919
/// Retrieve Object from paused serialized state.
2020
readonly $getObjectById$: (id: number | string) => any;
21-
$serverData$: Record<string, any>;
21+
serverData: Record<string, any>;
2222
$currentUniqueId$ = 0;
2323
$instanceHash$: string | null = null;
2424
$buildBase$: string | null = null;
@@ -29,7 +29,7 @@ export abstract class _SharedContainer implements Container {
2929
serverData: Record<string, any>,
3030
locale: string
3131
) {
32-
this.$serverData$ = serverData;
32+
this.serverData = serverData;
3333
this.$locale$ = locale;
3434
this.$version$ = version;
3535
this.$storeProxyMap$ = new WeakMap();

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

Lines changed: 28 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -621,7 +621,7 @@ type SeenRef = {
621621
let isDomRef = (obj: unknown): obj is DomRef => false;
622622

623623
export interface SerializationContext {
624-
$serialize$: () => void;
624+
serialize: () => void;
625625

626626
$symbolToChunkResolver$: SymbolToChunkResolver;
627627

@@ -647,7 +647,7 @@ export interface SerializationContext {
647647
* Returns a path string representing the path from roots through all parents to the object.
648648
* Format: "3 2 0" where each number is the index within its parent, from root to leaf.
649649
*/
650-
$addRoot$: (obj: unknown, parent?: unknown) => number;
650+
addRoot: (obj: unknown, parent?: unknown) => number;
651651

652652
/**
653653
* Get root path of the object without creating a new root.
@@ -660,7 +660,7 @@ export interface SerializationContext {
660660

661661
$seen$: (obj: unknown, parent: unknown | null, index: number) => void;
662662

663-
$roots$: unknown[];
663+
roots: unknown[];
664664
$pathMap$: Map<unknown, string | number>;
665665

666666
$addSyncFn$($funcStr$: string | null, argsCount: number, fn: Function): number;
@@ -671,7 +671,7 @@ export interface SerializationContext {
671671
$writer$: StreamWriter;
672672
$syncFns$: string[];
673673

674-
$eventQrls$: Set<QRL>;
674+
eventQrls: Set<QRL>;
675675
$eventNames$: Set<string>;
676676
$resources$: Set<ResourceReturnInternal<unknown>>;
677677
$renderSymbols$: Set<string>;
@@ -748,7 +748,7 @@ export const createSerializationContext = (
748748
return pathStr;
749749
};
750750

751-
const $addRoot$ = (obj: any, parent: unknown = null) => {
751+
const addRoot = (obj: any, parent: unknown = null) => {
752752
let seen = seenObjsMap.get(obj);
753753
if (!seen) {
754754
const rootIndex = roots.length;
@@ -771,20 +771,20 @@ export const createSerializationContext = (
771771
) as (obj: unknown) => obj is DomRef;
772772

773773
return {
774-
async $serialize$(): Promise<void> {
774+
async serialize(): Promise<void> {
775775
return await serialize(this);
776776
},
777777
$isSsrNode$: isSsrNode,
778778
$isDomRef$: isDomRef,
779779
$symbolToChunkResolver$: symbolToChunkResolver,
780780
$wasSeen$,
781-
$roots$: roots,
781+
roots,
782782
$seen$,
783783
$hasRootId$: (obj: any) => {
784784
const id = seenObjsMap.get(obj);
785785
return id?.$parent$ === null ? id.$index$ : undefined;
786786
},
787-
$addRoot$,
787+
addRoot,
788788
$addRootPath$,
789789
$syncFns$: syncFns,
790790
$addSyncFn$: (funcStr: string | null, argCount: number, fn: Function) => {
@@ -809,7 +809,7 @@ export const createSerializationContext = (
809809
return id;
810810
},
811811
$writer$: writer,
812-
$eventQrls$: new Set<QRL>(),
812+
eventQrls: new Set<QRL>(),
813813
$eventNames$: new Set<string>(),
814814
$resources$: new Set<ResourceReturnInternal<unknown>>(),
815815
$renderSymbols$: new Set<string>(),
@@ -827,7 +827,7 @@ function $discoverRoots$(
827827
parent: unknown,
828828
index: number
829829
): void {
830-
const { $wasSeen$, $seen$, $addRoot$ } = serializationContext;
830+
const { $wasSeen$, $seen$, addRoot: $addRoot$ } = serializationContext;
831831
if (!(shouldTrackObj(obj) || frameworkType(obj))) {
832832
return;
833833
}
@@ -879,8 +879,15 @@ class PromiseResult {
879879
* - Therefore root indexes need to be doubled to get the actual index.
880880
*/
881881
async function serialize(serializationContext: SerializationContext): Promise<void> {
882-
const { $writer$, $isSsrNode$, $isDomRef$, $storeProxyMap$, $addRoot$, $pathMap$, $wasSeen$ } =
883-
serializationContext;
882+
const {
883+
$writer$,
884+
$isSsrNode$,
885+
$isDomRef$,
886+
$storeProxyMap$,
887+
addRoot: $addRoot$,
888+
$pathMap$,
889+
$wasSeen$,
890+
} = serializationContext;
884891
let depth = 0;
885892
const forwardRefs: number[] = [];
886893
let forwardRefsId = 0;
@@ -930,7 +937,7 @@ async function serialize(serializationContext: SerializationContext): Promise<vo
930937

931938
const addPreloadQrl = (qrl: QRLInternal) => {
932939
preloadQrls.add(qrl);
933-
serializationContext.$addRoot$(qrl, null);
940+
serializationContext.addRoot(qrl, null);
934941
};
935942

936943
const outputRootRef = (value: unknown, elseCallback: () => void) => {
@@ -964,7 +971,7 @@ async function serialize(serializationContext: SerializationContext): Promise<vo
964971
if (isRootObject()) {
965972
output(type, qrl);
966973
} else {
967-
const id = serializationContext.$addRoot$(qrl);
974+
const id = serializationContext.addRoot(qrl);
968975
output(type, id);
969976
}
970977
});
@@ -1092,7 +1099,7 @@ async function serialize(serializationContext: SerializationContext): Promise<vo
10921099
if ($storeProxyMap$.has(propValue)) {
10931100
const innerStore = $storeProxyMap$.get(propValue);
10941101
innerStores.push(innerStore);
1095-
serializationContext.$addRoot$(innerStore);
1102+
serializationContext.addRoot(innerStore);
10961103
}
10971104
}
10981105

@@ -1318,7 +1325,7 @@ async function serialize(serializationContext: SerializationContext): Promise<vo
13181325
$writer$.write('[');
13191326

13201327
let lastRootsLength = 0;
1321-
let rootsLength = serializationContext.$roots$.length;
1328+
let rootsLength = serializationContext.roots.length;
13221329
while (lastRootsLength < rootsLength || promises.size) {
13231330
if (lastRootsLength !== 0) {
13241331
$writer$.write(',');
@@ -1331,7 +1338,7 @@ async function serialize(serializationContext: SerializationContext): Promise<vo
13311338
} else {
13321339
separator = true;
13331340
}
1334-
writeValue(serializationContext.$roots$[i]);
1341+
writeValue(serializationContext.roots[i]);
13351342
}
13361343

13371344
if (promises.size) {
@@ -1343,7 +1350,7 @@ async function serialize(serializationContext: SerializationContext): Promise<vo
13431350
}
13441351

13451352
lastRootsLength = rootsLength;
1346-
rootsLength = serializationContext.$roots$.length;
1353+
rootsLength = serializationContext.roots.length;
13471354
}
13481355

13491356
if (forwardRefs.length) {
@@ -1462,7 +1469,7 @@ export function qrlToString(
14621469
serializedReferences += ' ';
14631470
}
14641471
// We refer by id so every capture needs to be a root
1465-
serializedReferences += serializationContext.$addRoot$(value.$captureRef$[i]);
1472+
serializedReferences += serializationContext.addRoot(value.$captureRef$[i]);
14661473
}
14671474
qrlStringInline += `[${serializedReferences}]`;
14681475
} else if (value.$capture$ && value.$capture$.length > 0) {
@@ -1488,9 +1495,9 @@ export async function _serialize(data: unknown[]): Promise<string> {
14881495
);
14891496

14901497
for (const root of data) {
1491-
serializationContext.$addRoot$(root);
1498+
serializationContext.addRoot(root);
14921499
}
1493-
await serializationContext.$serialize$();
1500+
await serializationContext.serialize();
14941501
return serializationContext.$writer$.toString();
14951502
}
14961503

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1064,9 +1064,9 @@ async function serialize(...roots: any[]): Promise<any[]> {
10641064
null!
10651065
);
10661066
for (const root of roots) {
1067-
sCtx.$addRoot$(root, null);
1067+
sCtx.addRoot(root, null);
10681068
}
1069-
await sCtx.$serialize$();
1069+
await sCtx.serialize();
10701070
const objs = JSON.parse(sCtx.$writer$.toString());
10711071
// eslint-disable-next-line no-console
10721072
DEBUG && console.log(objs);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export interface Container {
2323
readonly $locale$: string;
2424
/// Retrieve Object from paused serialized state.
2525
readonly $getObjectById$: (id: number | string) => any;
26-
readonly $serverData$: Record<string, any>;
26+
readonly serverData: Record<string, any>;
2727
$currentUniqueId$: number;
2828
$buildBase$: string | null;
2929

packages/qwik/src/core/ssr/ssr-render-jsx.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -484,7 +484,7 @@ function addQwikEventToSerializationContext(
484484
const eventName = getEventNameFromJsxEvent(key);
485485
if (eventName) {
486486
serializationCtx.$eventNames$.add(eventName);
487-
serializationCtx.$eventQrls$.add(qrl);
487+
serializationCtx.eventQrls.add(qrl);
488488
}
489489
}
490490

packages/qwik/src/core/use/use-env-data.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,5 @@ export function useServerData<T, B = T>(key: string, defaultValue: B): T | B;
99
/** @public */
1010
export function useServerData(key: string, defaultValue?: any) {
1111
const ctx = tryGetInvokeContext();
12-
return ctx?.$container$?.$serverData$[key] ?? defaultValue;
12+
return ctx?.$container$?.serverData[key] ?? defaultValue;
1313
}

0 commit comments

Comments
 (0)