Skip to content

Commit ed307f3

Browse files
committed
chore(serialized$): clean up/types
1 parent 1badea0 commit ed307f3

File tree

12 files changed

+172
-130
lines changed

12 files changed

+172
-130
lines changed

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

Lines changed: 6 additions & 6 deletions
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
},
@@ -1901,8 +1901,8 @@
19011901
}
19021902
],
19031903
"kind": "Function",
1904-
"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;",
1905-
"editUrl": "https://github.com/QwikDev/qwik/tree/main/packages/qwik/src/core/use/use-computed-dollar.ts",
1904+
"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;",
1905+
"editUrl": "https://github.com/QwikDev/qwik/tree/main/packages/qwik/src/core/use/use-computed.ts",
19061906
"mdFile": "core.usecomputed_.md"
19071907
},
19081908
{
@@ -2041,8 +2041,8 @@
20412041
}
20422042
],
20432043
"kind": "Variable",
2044-
"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```",
2045-
"editUrl": "https://github.com/QwikDev/qwik/tree/main/packages/qwik/src/core/use/use-serializer.ts",
2044+
"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```",
2045+
"editUrl": "https://github.com/QwikDev/qwik/tree/main/packages/qwik/src/core/use/use-serialized.ts",
20462046
"mdFile": "core.useserialized_.md"
20472047
},
20482048
{

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

Lines changed: 13 additions & 19 deletions
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

@@ -4453,7 +4449,7 @@ Creates a computed signal which is calculated from the given function. A compute
44534449
The function must be synchronous and must not have any side effects.
44544450
44554451
```typescript
4456-
useComputed$: <T>(qrl: import("./use-computed").ComputedFn<T>) => T extends Promise<any> ? never : import("..").ReadonlySignal<T>
4452+
useComputed$: <T>(qrl: ComputedFn<T>) => T extends Promise<any> ? never : ReadonlySignal<T>
44574453
```
44584454
44594455
<table><thead><tr><th>
@@ -4475,17 +4471,17 @@ qrl
44754471
44764472
</td><td>
44774473
4478-
import("./use-computed").[ComputedFn](#computedfn)&lt;T&gt;
4474+
[ComputedFn](#computedfn)&lt;T&gt;
44794475
44804476
</td><td>
44814477
44824478
</td></tr>
44834479
</tbody></table>
44844480
**Returns:**
44854481
4486-
T extends Promise&lt;any&gt; ? never : import("..").[ReadonlySignal](#readonlysignal)&lt;T&gt;
4482+
T extends Promise&lt;any&gt; ? never : [ReadonlySignal](#readonlysignal)&lt;T&gt;
44874483
4488-
[Edit this section](https://github.com/QwikDev/qwik/tree/main/packages/qwik/src/core/use/use-computed-dollar.ts)
4484+
[Edit this section](https://github.com/QwikDev/qwik/tree/main/packages/qwik/src/core/use/use-computed.ts)
44894485
44904486
## useConstant
44914487
@@ -4953,9 +4949,7 @@ This is useful when using third party libraries that use custom objects that are
49534949
Note that the `fn` is called lazily, so it won't impact container resume.
49544950
49554951
```typescript
4956-
useSerialized$: {
4957-
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>;
4958-
}['fn']
4952+
useSerialized$: typeof createSerialized$;
49594953
```
49604954
49614955
```tsx
@@ -4979,7 +4973,7 @@ const Cmp = component$(() => {
49794973
});
49804974
```
49814975
4982-
[Edit this section](https://github.com/QwikDev/qwik/tree/main/packages/qwik/src/core/use/use-serializer.ts)
4976+
[Edit this section](https://github.com/QwikDev/qwik/tree/main/packages/qwik/src/core/use/use-serialized.ts)
49834977
49844978
## useServerData
49854979

packages/qwik/src/core/api.md

Lines changed: 10 additions & 8 deletions
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: {
@@ -1109,14 +1113,12 @@ export const useResource$: <T>(generatorFn: ResourceFn<T>, opts?: ResourceOption
11091113
export const useResourceQrl: <T>(qrl: QRL<ResourceFn<T>>, opts?: ResourceOptions) => ResourceReturn<T>;
11101114

11111115
// @public
1112-
export const useSerialized$: {
1113-
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>;
1114-
}['fn'];
1116+
export const useSerialized$: typeof createSerialized$;
11151117

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

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

packages/qwik/src/core/index.ts

Lines changed: 1 addition & 1 deletion
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

Lines changed: 8 additions & 11 deletions
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)