Skip to content

Commit dff8516

Browse files
committed
chore(serialized$): clean up/types
1 parent 33ba20f commit dff8516

File tree

12 files changed

+172
-130
lines changed

12 files changed

+172
-130
lines changed

packages/docs/src/routes/api/qwik/api.json

+6-6
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@
203203
}
204204
],
205205
"kind": "Function",
206-
"content": "Create a computed signal which is calculated from the given QRL. A computed signal is a signal which is calculated from other signals. When the signals change, the computed signal is recalculated.\n\nThe QRL must be a function which returns the value of the signal. The function must not have side effects, and it mus be synchronous.\n\nIf you need the function to be async, use `useSignal` and `useTask$` instead.\n\n\n```typescript\ncreateComputed$: <T>(qrl: () => T) => T extends Promise<any> ? never : ComputedSignal<T>\n```\n\n\n<table><thead><tr><th>\n\nParameter\n\n\n</th><th>\n\nType\n\n\n</th><th>\n\nDescription\n\n\n</th></tr></thead>\n<tbody><tr><td>\n\nqrl\n\n\n</td><td>\n\n() =&gt; T\n\n\n</td><td>\n\n\n</td></tr>\n</tbody></table>\n**Returns:**\n\nT extends Promise&lt;any&gt; ? never : [ComputedSignal](#computedsignal)<!-- -->&lt;T&gt;",
206+
"content": "Create a computed signal which is calculated from the given QRL. A computed signal is a signal which is calculated from other signals. When the signals change, the computed signal is recalculated.\n\nThe QRL must be a function which returns the value of the signal. The function must not have side effects, and it must be synchronous.\n\nIf you need the function to be async, use `useSignal` and `useTask$` instead.\n\n\n```typescript\ncreateComputed$: <T>(qrl: () => T) => T extends Promise<any> ? never : ComputedSignal<T>\n```\n\n\n<table><thead><tr><th>\n\nParameter\n\n\n</th><th>\n\nType\n\n\n</th><th>\n\nDescription\n\n\n</th></tr></thead>\n<tbody><tr><td>\n\nqrl\n\n\n</td><td>\n\n() =&gt; T\n\n\n</td><td>\n\n\n</td></tr>\n</tbody></table>\n**Returns:**\n\nT extends Promise&lt;any&gt; ? never : [ComputedSignal](#computedsignal)<!-- -->&lt;T&gt;",
207207
"editUrl": "https://github.com/QwikDev/qwik/tree/main/packages/qwik/src/core/signal/signal.public.ts",
208208
"mdFile": "core.createcomputed_.md"
209209
},
@@ -231,7 +231,7 @@
231231
}
232232
],
233233
"kind": "Function",
234-
"content": "Create a signal that holds a custom serializable value. See `useSerialized$` for more details.\n\n\n```typescript\ncreateSerialized$: <T extends CustomSerializable<T, S>, S, F extends ConstructorFn<T, S> = ConstructorFn<T, S>>(qrl: F | QRL<F>) => SerializedSignal<T, S, F>\n```\n\n\n<table><thead><tr><th>\n\nParameter\n\n\n</th><th>\n\nType\n\n\n</th><th>\n\nDescription\n\n\n</th></tr></thead>\n<tbody><tr><td>\n\nqrl\n\n\n</td><td>\n\nF \\| [QRL](#qrl)<!-- -->&lt;F&gt;\n\n\n</td><td>\n\n\n</td></tr>\n</tbody></table>\n**Returns:**\n\nSerializedSignal&lt;T, S, F&gt;",
234+
"content": "Create a signal that holds a custom serializable value. See [useSerialized$](#useserialized_) for more details.\n\n\n```typescript\ncreateSerialized$: <T extends CustomSerializable<any, S>, S = T extends {\n [SerializerSymbol]: (obj: any) => infer U;\n} ? U : unknown>(qrl: (data: S | undefined) => T) => T extends Promise<any> ? never : SerializedSignal<T>\n```\n\n\n<table><thead><tr><th>\n\nParameter\n\n\n</th><th>\n\nType\n\n\n</th><th>\n\nDescription\n\n\n</th></tr></thead>\n<tbody><tr><td>\n\nqrl\n\n\n</td><td>\n\n(data: S \\| undefined) =&gt; T\n\n\n</td><td>\n\n\n</td></tr>\n</tbody></table>\n**Returns:**\n\nT extends Promise&lt;any&gt; ? never : SerializedSignal&lt;T&gt;",
235235
"editUrl": "https://github.com/QwikDev/qwik/tree/main/packages/qwik/src/core/signal/signal.public.ts",
236236
"mdFile": "core.createserialized_.md"
237237
},
@@ -1915,8 +1915,8 @@
19151915
}
19161916
],
19171917
"kind": "Function",
1918-
"content": "Creates a computed signal which is calculated from the given function. A computed signal is a signal which is calculated from other signals. When the signals change, the computed signal is recalculated, and if the result changed, all tasks which are tracking the signal will be re-run and all components that read the signal will be re-rendered.\n\nThe function must be synchronous and must not have any side effects.\n\n\n```typescript\nuseComputed$: <T>(qrl: import(\"./use-computed\").ComputedFn<T>) => T extends Promise<any> ? never : import(\"..\").ReadonlySignal<T>\n```\n\n\n<table><thead><tr><th>\n\nParameter\n\n\n</th><th>\n\nType\n\n\n</th><th>\n\nDescription\n\n\n</th></tr></thead>\n<tbody><tr><td>\n\nqrl\n\n\n</td><td>\n\nimport(\"./use-computed\").[ComputedFn](#computedfn)<!-- -->&lt;T&gt;\n\n\n</td><td>\n\n\n</td></tr>\n</tbody></table>\n**Returns:**\n\nT extends Promise&lt;any&gt; ? never : import(\"..\").[ReadonlySignal](#readonlysignal)<!-- -->&lt;T&gt;",
1919-
"editUrl": "https://github.com/QwikDev/qwik/tree/main/packages/qwik/src/core/use/use-computed-dollar.ts",
1918+
"content": "Creates a computed signal which is calculated from the given function. A computed signal is a signal which is calculated from other signals. When the signals change, the computed signal is recalculated, and if the result changed, all tasks which are tracking the signal will be re-run and all components that read the signal will be re-rendered.\n\nThe function must be synchronous and must not have any side effects.\n\n\n```typescript\nuseComputed$: <T>(qrl: ComputedFn<T>) => T extends Promise<any> ? never : ReadonlySignal<T>\n```\n\n\n<table><thead><tr><th>\n\nParameter\n\n\n</th><th>\n\nType\n\n\n</th><th>\n\nDescription\n\n\n</th></tr></thead>\n<tbody><tr><td>\n\nqrl\n\n\n</td><td>\n\n[ComputedFn](#computedfn)<!-- -->&lt;T&gt;\n\n\n</td><td>\n\n\n</td></tr>\n</tbody></table>\n**Returns:**\n\nT extends Promise&lt;any&gt; ? never : [ReadonlySignal](#readonlysignal)<!-- -->&lt;T&gt;",
1919+
"editUrl": "https://github.com/QwikDev/qwik/tree/main/packages/qwik/src/core/use/use-computed.ts",
19201920
"mdFile": "core.usecomputed_.md"
19211921
},
19221922
{
@@ -2055,8 +2055,8 @@
20552055
}
20562056
],
20572057
"kind": "Variable",
2058-
"content": "Creates a signal which holds a custom serializable value. It requires that the value implements the `CustomSerializable` type, which means having a function under the `[SerializeSymbol]` property that returns a serializable value when called.\n\nThe `fn` you pass is called with the result of the serialization (in the browser, only when the value is needed), or `undefined` when not yet initialized. If you refer to other signals, `fn` will be called when those change just like computed signals, and then the argument will be the previous output, not the serialized result.\n\nThis is useful when using third party libraries that use custom objects that are not serializable.\n\nNote that the `fn` is called lazily, so it won't impact container resume.\n\n\n```typescript\nuseSerialized$: {\n fn: <T extends CustomSerializable<T, S>, S, F extends ConstructorFn<T, S> = ConstructorFn<T, S>>(fn: F | QRL<F>) => T extends Promise<any> ? never : ReadonlySignal<T>;\n}['fn']\n```\n\n\n\n```tsx\nclass MyCustomSerializable {\n constructor(public n: number) {}\n inc() {\n this.n++;\n }\n [SerializeSymbol]() {\n return this.n;\n }\n}\nconst Cmp = component$(() => {\n const custom = useSerialized$<MyCustomSerializable, number>(\n (prev) =>\n new MyCustomSerializable(prev instanceof MyCustomSerializable ? prev : (prev ?? 3))\n );\n return <div onClick$={() => custom.value.inc()}>{custom.value.n}</div>;\n});\n```",
2059-
"editUrl": "https://github.com/QwikDev/qwik/tree/main/packages/qwik/src/core/use/use-serializer.ts",
2058+
"content": "Creates a signal which holds a custom serializable value. It requires that the value implements the `CustomSerializable` type, which means having a function under the `[SerializeSymbol]` property that returns a serializable value when called.\n\nThe `fn` you pass is called with the result of the serialization (in the browser, only when the value is needed), or `undefined` when not yet initialized. If you refer to other signals, `fn` will be called when those change just like computed signals, and then the argument will be the previous output, not the serialized result.\n\nThis is useful when using third party libraries that use custom objects that are not serializable.\n\nNote that the `fn` is called lazily, so it won't impact container resume.\n\n\n```typescript\nuseSerialized$: typeof createSerialized$\n```\n\n\n\n```tsx\nclass MyCustomSerializable {\n constructor(public n: number) {}\n inc() {\n this.n++;\n }\n [SerializeSymbol]() {\n return this.n;\n }\n}\nconst Cmp = component$(() => {\n const custom = useSerialized$<MyCustomSerializable, number>(\n (prev) =>\n new MyCustomSerializable(prev instanceof MyCustomSerializable ? prev : (prev ?? 3))\n );\n return <div onClick$={() => custom.value.inc()}>{custom.value.n}</div>;\n});\n```",
2059+
"editUrl": "https://github.com/QwikDev/qwik/tree/main/packages/qwik/src/core/use/use-serialized.ts",
20602060
"mdFile": "core.useserialized_.md"
20612061
},
20622062
{

packages/docs/src/routes/api/qwik/index.md

+13-19
Original file line numberDiff line numberDiff line change
@@ -603,7 +603,7 @@ Description
603603
604604
Create a computed signal which is calculated from the given QRL. A computed signal is a signal which is calculated from other signals. When the signals change, the computed signal is recalculated.
605605
606-
The QRL must be a function which returns the value of the signal. The function must not have side effects, and it mus be synchronous.
606+
The QRL must be a function which returns the value of the signal. The function must not have side effects, and it must be synchronous.
607607
608608
If you need the function to be async, use `useSignal` and `useTask$` instead.
609609
@@ -725,16 +725,12 @@ The name of the context.
725725

726726
## createSerialized$
727727

728-
Create a signal that holds a custom serializable value. See `useSerialized$` for more details.
728+
Create a signal that holds a custom serializable value. See [useSerialized$](#useserialized_) for more details.
729729

730730
```typescript
731-
createSerialized$: <
732-
T extends CustomSerializable<T, S>,
733-
S,
734-
F extends ConstructorFn<T, S> = ConstructorFn<T, S>,
735-
>(
736-
qrl: F | QRL<F>,
737-
) => SerializedSignal<T, S, F>;
731+
createSerialized$: <T extends CustomSerializable<any, S>, S = T extends {
732+
[SerializerSymbol]: (obj: any) => infer U;
733+
} ? U : unknown>(qrl: (data: S | undefined) => T) => T extends Promise<any> ? never : SerializedSignal<T>
738734
```
739735

740736
<table><thead><tr><th>
@@ -756,15 +752,15 @@ qrl
756752

757753
</td><td>
758754

759-
F \| [QRL](#qrl)&lt;F&gt;
755+
(data: S \| undefined) =&gt; T
760756

761757
</td><td>
762758

763759
</td></tr>
764760
</tbody></table>
765761
**Returns:**
766762

767-
SerializedSignal&lt;T, S, F&gt;
763+
T extends Promise&lt;any&gt; ? never : SerializedSignal&lt;T&gt;
768764

769765
[Edit this section](https://github.com/QwikDev/qwik/tree/main/packages/qwik/src/core/signal/signal.public.ts)
770766

@@ -4461,7 +4457,7 @@ Creates a computed signal which is calculated from the given function. A compute
44614457
The function must be synchronous and must not have any side effects.
44624458
44634459
```typescript
4464-
useComputed$: <T>(qrl: import("./use-computed").ComputedFn<T>) => T extends Promise<any> ? never : import("..").ReadonlySignal<T>
4460+
useComputed$: <T>(qrl: ComputedFn<T>) => T extends Promise<any> ? never : ReadonlySignal<T>
44654461
```
44664462
44674463
<table><thead><tr><th>
@@ -4483,17 +4479,17 @@ qrl
44834479
44844480
</td><td>
44854481
4486-
import("./use-computed").[ComputedFn](#computedfn)&lt;T&gt;
4482+
[ComputedFn](#computedfn)&lt;T&gt;
44874483
44884484
</td><td>
44894485
44904486
</td></tr>
44914487
</tbody></table>
44924488
**Returns:**
44934489
4494-
T extends Promise&lt;any&gt; ? never : import("..").[ReadonlySignal](#readonlysignal)&lt;T&gt;
4490+
T extends Promise&lt;any&gt; ? never : [ReadonlySignal](#readonlysignal)&lt;T&gt;
44954491
4496-
[Edit this section](https://github.com/QwikDev/qwik/tree/main/packages/qwik/src/core/use/use-computed-dollar.ts)
4492+
[Edit this section](https://github.com/QwikDev/qwik/tree/main/packages/qwik/src/core/use/use-computed.ts)
44974493
44984494
## useConstant
44994495
@@ -4961,9 +4957,7 @@ This is useful when using third party libraries that use custom objects that are
49614957
Note that the `fn` is called lazily, so it won't impact container resume.
49624958
49634959
```typescript
4964-
useSerialized$: {
4965-
fn: <T extends CustomSerializable<T, S>, S, F extends ConstructorFn<T, S> = ConstructorFn<T, S>>(fn: F | QRL<F>) => T extends Promise<any> ? never : ReadonlySignal<T>;
4966-
}['fn']
4960+
useSerialized$: typeof createSerialized$;
49674961
```
49684962
49694963
```tsx
@@ -4987,7 +4981,7 @@ const Cmp = component$(() => {
49874981
});
49884982
```
49894983
4990-
[Edit this section](https://github.com/QwikDev/qwik/tree/main/packages/qwik/src/core/use/use-serializer.ts)
4984+
[Edit this section](https://github.com/QwikDev/qwik/tree/main/packages/qwik/src/core/use/use-serialized.ts)
49914985
49924986
## useServerData
49934987

packages/qwik/src/core/api.md

+10-8
Original file line numberDiff line numberDiff line change
@@ -111,25 +111,29 @@ export interface CorrectedToggleEvent extends Event {
111111
// @public
112112
export const createComputed$: <T>(qrl: () => T) => T extends Promise<any> ? never : ComputedSignal<T>;
113113

114+
// Warning: (ae-forgotten-export) The symbol "ComputedSignal_2" needs to be exported by the entry point index.d.ts
114115
// Warning: (ae-internal-missing-underscore) The name "createComputedQrl" should be prefixed with an underscore because the declaration is marked as @internal
115116
//
116117
// @internal (undocumented)
117-
export const createComputedQrl: <T>(qrl: QRL<() => T>) => T extends Promise<any> ? never : ComputedSignal<T>;
118+
export const createComputedQrl: <T>(qrl: QRL<() => T>) => ComputedSignal_2<T>;
118119

119120
// @public
120121
export const createContextId: <STATE = unknown>(name: string) => ContextId<STATE>;
121122

122123
// Warning: (ae-forgotten-export) The symbol "CustomSerializable" needs to be exported by the entry point index.d.ts
123-
// Warning: (ae-forgotten-export) The symbol "ConstructorFn" needs to be exported by the entry point index.d.ts
124124
// Warning: (ae-forgotten-export) The symbol "SerializedSignal" needs to be exported by the entry point index.d.ts
125125
//
126126
// @public
127-
export const createSerialized$: <T extends CustomSerializable<T, S>, S, F extends ConstructorFn<T, S> = ConstructorFn<T, S>>(qrl: F | QRL<F>) => SerializedSignal<T, S, F>;
127+
export const createSerialized$: <T extends CustomSerializable<any, S>, S = T extends {
128+
[SerializerSymbol]: (obj: any) => infer U;
129+
} ? U : unknown>(qrl: (data: S | undefined) => T) => T extends Promise<any> ? never : SerializedSignal<T>;
128130

131+
// Warning: (ae-forgotten-export) The symbol "ConstructorFn" needs to be exported by the entry point index.d.ts
132+
// Warning: (ae-forgotten-export) The symbol "SerializedSignal_2" needs to be exported by the entry point index.d.ts
129133
// Warning: (ae-internal-missing-underscore) The name "createSerializedQrl" should be prefixed with an underscore because the declaration is marked as @internal
130134
//
131135
// @internal (undocumented)
132-
export const createSerializedQrl: <T extends CustomSerializable<T, S>, S, F extends ConstructorFn<T, S> = ConstructorFn<T, S>>(qrl: QRL<F>) => SerializedSignal<T, S, F>;
136+
export const createSerializedQrl: <T extends CustomSerializable<T, S>, S>(qrl: QRL<ConstructorFn<T, S>>) => SerializedSignal_2<T>;
133137

134138
// @public
135139
export const createSignal: {
@@ -1105,14 +1109,12 @@ export const useResource$: <T>(generatorFn: ResourceFn<T>, opts?: ResourceOption
11051109
export const useResourceQrl: <T>(qrl: QRL<ResourceFn<T>>, opts?: ResourceOptions) => ResourceReturn<T>;
11061110

11071111
// @public
1108-
export const useSerialized$: {
1109-
fn: <T extends CustomSerializable<T, S>, S, F extends ConstructorFn<T, S> = ConstructorFn<T, S>>(fn: F | QRL<F>) => T extends Promise<any> ? never : ReadonlySignal<T>;
1110-
}['fn'];
1112+
export const useSerialized$: typeof createSerialized$;
11111113

11121114
// Warning: (ae-internal-missing-underscore) The name "useSerializedQrl" should be prefixed with an underscore because the declaration is marked as @internal
11131115
//
11141116
// @internal (undocumented)
1115-
export const useSerializedQrl: <T extends CustomSerializable<T, S>, S, F extends ConstructorFn<T, S>>(qrl: QRL<F>) => T extends Promise<any> ? never : ReadonlySignal<T>;
1117+
export const useSerializedQrl: <F extends ConstructorFn<any, any>>(qrl: QRL<F>) => ReadonlySignal<unknown>;
11161118

11171119
// @public (undocumented)
11181120
export function useServerData<T>(key: string): T | undefined;

packages/qwik/src/core/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ export { useResource$ } from './use/use-resource-dollar';
129129
export { useTaskQrl } from './use/use-task';
130130
export { useTask$ } from './use/use-task-dollar';
131131
export { useVisibleTask$ } from './use/use-visible-task-dollar';
132-
export { useComputed$ } from './use/use-computed-dollar';
132+
export { useComputed$ } from './use/use-computed';
133133
export { useErrorBoundary } from './use/use-error-boundary';
134134
export type { ErrorBoundaryStore } from './shared/error/error-handling';
135135
export { type ReadonlySignal, type Signal, type ComputedSignal } from './signal/signal.public';

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

+8-11
Original file line numberDiff line numberDiff line change
@@ -3,31 +3,28 @@ import type { QRL } from '../shared/qrl/qrl.public';
33
import {
44
ComputedSignal,
55
SerializedSignal,
6-
Signal,
6+
Signal as SignalImpl,
77
throwIfQRLNotResolved,
88
type ConstructorFn,
99
type CustomSerializable,
1010
} from './signal';
11+
import type { Signal } from './signal.public';
1112

1213
/** @internal */
13-
export const createSignal = <T>(value?: T) => {
14-
return new Signal(null, value);
14+
export const createSignal = <T>(value?: T): Signal<T> => {
15+
return new SignalImpl(null, value as T) as Signal<T>;
1516
};
1617

1718
/** @internal */
18-
export const createComputedSignal = <T>(qrl: QRL<() => T>) => {
19+
export const createComputedSignal = <T>(qrl: QRL<() => T>): ComputedSignal<T> => {
1920
throwIfQRLNotResolved(qrl);
2021
return new ComputedSignal<T>(null, qrl as QRLInternal<() => T>);
2122
};
2223

2324
/** @internal */
24-
export const createSerializedSignal = <
25-
T extends CustomSerializable<T, S>,
26-
S,
27-
F extends ConstructorFn<T, S> = ConstructorFn<T, S>,
28-
>(
29-
qrl: QRL<F>
25+
export const createSerializedSignal = <T extends CustomSerializable<T, S>, S>(
26+
qrl: QRL<ConstructorFn<T, S>>
3027
) => {
3128
throwIfQRLNotResolved(qrl);
32-
return new SerializedSignal<T, S, F>(null, qrl);
29+
return new SerializedSignal<T>(null, qrl);
3330
};

0 commit comments

Comments
 (0)