Skip to content

Commit fce698c

Browse files
committed
move track and cleanup logic to shared file
1 parent 8db4751 commit fce698c

File tree

16 files changed

+205
-249
lines changed

16 files changed

+205
-249
lines changed

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

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@
244244
}
245245
],
246246
"kind": "Interface",
247-
"content": "```typescript\nexport interface AsyncComputedReadonlySignal<T = unknown> extends ReadonlySignal<T> \n```\n**Extends:** [ReadonlySignal](#readonlysignal)<!-- -->&lt;T&gt;\n\n\n<table><thead><tr><th>\n\nProperty\n\n\n</th><th>\n\nModifiers\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\n[error](#)\n\n\n</td><td>\n\n\n</td><td>\n\nError \\| null\n\n\n</td><td>\n\n\n</td></tr>\n<tr><td>\n\n[pending](#)\n\n\n</td><td>\n\n\n</td><td>\n\nboolean\n\n\n</td><td>\n\n\n</td></tr>\n</tbody></table>",
247+
"content": "```typescript\nexport interface AsyncComputedReadonlySignal<T = unknown> extends ReadonlySignal<T> \n```\n**Extends:** [ReadonlySignal](#readonlysignal)<!-- -->&lt;T&gt;",
248248
"editUrl": "https://github.com/QwikDev/qwik/tree/main/packages/qwik/src/core/reactive-primitives/signal.public.ts",
249249
"mdFile": "core.asynccomputedreadonlysignal.md"
250250
},
@@ -366,6 +366,20 @@
366366
"editUrl": "https://github.com/QwikDev/qwik/tree/main/packages/qwik/src/core/use/use-computed.ts",
367367
"mdFile": "core.computedfn.md"
368368
},
369+
{
370+
"name": "ComputedReturnType",
371+
"id": "computedreturntype",
372+
"hierarchy": [
373+
{
374+
"name": "ComputedReturnType",
375+
"id": "computedreturntype"
376+
}
377+
],
378+
"kind": "TypeAlias",
379+
"content": "```typescript\nexport type ComputedReturnType<T> = T extends Promise<any> ? never : ReadonlySignal<T>;\n```\n**References:** [ReadonlySignal](#readonlysignal)",
380+
"editUrl": "https://github.com/QwikDev/qwik/tree/main/packages/qwik/src/core/use/use-computed.ts",
381+
"mdFile": "core.computedreturntype.md"
382+
},
369383
{
370384
"name": "ComputedSignal",
371385
"id": "computedsignal",
@@ -2102,7 +2116,7 @@
21022116
}
21032117
],
21042118
"kind": "Interface",
2105-
"content": "```typescript\nexport interface TaskCtx \n```\n\n\n<table><thead><tr><th>\n\nProperty\n\n\n</th><th>\n\nModifiers\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\n[track](#)\n\n\n</td><td>\n\n\n</td><td>\n\n[Tracker](#tracker)\n\n\n</td><td>\n\n\n</td></tr>\n</tbody></table>\n\n\n<table><thead><tr><th>\n\nMethod\n\n\n</th><th>\n\nDescription\n\n\n</th></tr></thead>\n<tbody><tr><td>\n\n[cleanup(callback)](#)\n\n\n</td><td>\n\n\n</td></tr>\n</tbody></table>",
2119+
"content": "```typescript\nexport interface TaskCtx \n```\n\n\n<table><thead><tr><th>\n\nProperty\n\n\n</th><th>\n\nModifiers\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\n[cleanup](#)\n\n\n</td><td>\n\n\n</td><td>\n\n(callback: () =&gt; void) =&gt; void\n\n\n</td><td>\n\n\n</td></tr>\n<tr><td>\n\n[track](#)\n\n\n</td><td>\n\n\n</td><td>\n\n[Tracker](#tracker)\n\n\n</td><td>\n\n\n</td></tr>\n</tbody></table>",
21062120
"editUrl": "https://github.com/QwikDev/qwik/tree/main/packages/qwik/src/core/use/use-task.ts",
21072121
"mdFile": "core.taskctx.md"
21082122
},
@@ -2186,7 +2200,7 @@
21862200
}
21872201
],
21882202
"kind": "Function",
2189-
"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;",
2203+
"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>) => ComputedReturnType<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\n[ComputedReturnType](#computedreturntype)<!-- -->&lt;T&gt;",
21902204
"editUrl": "https://github.com/QwikDev/qwik/tree/main/packages/qwik/src/core/use/use-computed.ts",
21912205
"mdFile": "core.usecomputed_.md"
21922206
},

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

Lines changed: 20 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -135,51 +135,6 @@ export interface AsyncComputedReadonlySignal<T = unknown> extends ReadonlySignal
135135
136136
**Extends:** [ReadonlySignal](#readonlysignal)&lt;T&gt;
137137
138-
<table><thead><tr><th>
139-
140-
Property
141-
142-
</th><th>
143-
144-
Modifiers
145-
146-
</th><th>
147-
148-
Type
149-
150-
</th><th>
151-
152-
Description
153-
154-
</th></tr></thead>
155-
<tbody><tr><td>
156-
157-
[error](#)
158-
159-
</td><td>
160-
161-
</td><td>
162-
163-
Error \| null
164-
165-
</td><td>
166-
167-
</td></tr>
168-
<tr><td>
169-
170-
[pending](#)
171-
172-
</td><td>
173-
174-
</td><td>
175-
176-
boolean
177-
178-
</td><td>
179-
180-
</td></tr>
181-
</tbody></table>
182-
183138
[Edit this section](https://github.com/QwikDev/qwik/tree/main/packages/qwik/src/core/reactive-primitives/signal.public.ts)
184139
185140
## AsyncComputedReturnType
@@ -429,6 +384,17 @@ export type ComputedFn<T> = () => T;
429384

430385
[Edit this section](https://github.com/QwikDev/qwik/tree/main/packages/qwik/src/core/use/use-computed.ts)
431386

387+
## ComputedReturnType
388+
389+
```typescript
390+
export type ComputedReturnType<T> =
391+
T extends Promise<any> ? never : ReadonlySignal<T>;
392+
```
393+
394+
**References:** [ReadonlySignal](#readonlysignal)
395+
396+
[Edit this section](https://github.com/QwikDev/qwik/tree/main/packages/qwik/src/core/use/use-computed.ts)
397+
432398
## ComputedSignal
433399
434400
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.
@@ -8343,31 +8309,26 @@ Description
83438309
</th></tr></thead>
83448310
<tbody><tr><td>
83458311
8346-
[track](#)
8312+
[cleanup](#)
83478313
83488314
</td><td>
83498315
83508316
</td><td>
83518317
8352-
[Tracker](#tracker)
8318+
(callback: () =&gt; void) =&gt; void
83538319
83548320
</td><td>
83558321
83568322
</td></tr>
8357-
</tbody></table>
8358-
8359-
<table><thead><tr><th>
8360-
8361-
Method
8323+
<tr><td>
83628324
8363-
</th><th>
8325+
[track](#)
83648326
8365-
Description
8327+
</td><td>
83668328
8367-
</th></tr></thead>
8368-
<tbody><tr><td>
8329+
</td><td>
83698330
8370-
[cleanup(callback)](#)
8331+
[Tracker](#tracker)
83718332
83728333
</td><td>
83738334
@@ -8557,7 +8518,7 @@ Creates a computed signal which is calculated from the given function. A compute
85578518
The function must be synchronous and must not have any side effects.
85588519
85598520
```typescript
8560-
useComputed$: <T>(qrl: ComputedFn<T>) => T extends Promise<any> ? never : ReadonlySignal<T>
8521+
useComputed$: <T>(qrl: ComputedFn<T>) => ComputedReturnType<T>;
85618522
```
85628523
85638524
<table><thead><tr><th>
@@ -8587,7 +8548,7 @@ qrl
85878548
</tbody></table>
85888549
**Returns:**
85898550
8590-
T extends Promise&lt;any&gt; ? never : [ReadonlySignal](#readonlysignal)&lt;T&gt;
8551+
[ComputedReturnType](#computedreturntype)&lt;T&gt;
85918552
85928553
[Edit this section](https://github.com/QwikDev/qwik/tree/main/packages/qwik/src/core/use/use-computed.ts)
85938554

packages/qwik/src/core/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ export type { UseStylesScoped } from './use/use-styles';
111111
export type { UseSignal } from './use/use-signal';
112112
export type { ContextId } from './use/use-context';
113113
export type { UseStoreOptions } from './use/use-store.public';
114-
export type { ComputedFn } from './use/use-computed';
114+
export type { ComputedFn, ComputedReturnType } from './use/use-computed';
115115
export { useComputedQrl } from './use/use-computed';
116116
export { useSerializerQrl, useSerializer$ } from './use/use-serializer';
117117
export type { OnVisibleTaskOptions, VisibleTaskStrategy } from './use/use-visible-task';

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

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,6 @@ export type AsyncComputedFn<T> = (ctx: AsyncComputedCtx) => Promise<T>;
2323

2424
// @public (undocumented)
2525
export interface AsyncComputedReadonlySignal<T = unknown> extends ReadonlySignal<T> {
26-
// (undocumented)
27-
error: Error | null;
28-
// (undocumented)
29-
pending: boolean;
3026
}
3127

3228
// @public (undocumented)
@@ -91,7 +87,7 @@ export const componentQrl: <PROPS extends Record<any, any>>(componentQrl: QRL<On
9187
export type ComputedFn<T> = () => T;
9288

9389
// @public (undocumented)
94-
export type ComputedReturnType<T> = T extends Promise<infer T> ? ReadonlySignal<T> : ReadonlySignal<T>;
90+
export type ComputedReturnType<T> = T extends Promise<any> ? never : ReadonlySignal<T>;
9591

9692
// @public
9793
export interface ComputedSignal<T> extends ReadonlySignal<T> {
@@ -262,6 +258,9 @@ class DomContainer extends _SharedContainer implements ClientContainer {
262258
export { DomContainer }
263259
export { DomContainer as _DomContainer }
264260

261+
// @internal (undocumented)
262+
export const _dumpState: (state: unknown[], color?: boolean, prefix?: string, limit?: number | null) => string;
263+
265264
// @internal (undocumented)
266265
export const _EFFECT_BACK_REF: unique symbol;
267266

@@ -567,6 +566,11 @@ export const PrefetchServiceWorker: (opts: {
567566
nonce?: string;
568567
}) => JSXOutput;
569568

569+
// Warning: (ae-forgotten-export) The symbol "DeserializeContainer" needs to be exported by the entry point index.d.ts
570+
//
571+
// @internal
572+
export function _preprocessState(data: unknown[], container: DeserializeContainer): void;
573+
570574
// @public
571575
export type PropFunction<T> = QRL<T>;
572576

@@ -1594,7 +1598,7 @@ export const _task: (_event: Event, element: Element) => void;
15941598
// @public (undocumented)
15951599
export interface TaskCtx {
15961600
// (undocumented)
1597-
cleanup(callback: () => void): void;
1601+
cleanup: (callback: () => void) => void;
15981602
// (undocumented)
15991603
track: Tracker;
16001604
}
@@ -1798,6 +1802,9 @@ export type VisibleTaskStrategy = 'intersection-observer' | 'document-ready' | '
17981802
// @internal (undocumented)
17991803
export type _VNode = _ElementVNode | _TextVNode | _VirtualVNode;
18001804

1805+
// @internal (undocumented)
1806+
export function _vnode_toString(this: _VNode | null, depth?: number, offset?: string, materialize?: boolean, siblings?: boolean, colorize?: boolean): string;
1807+
18011808
// @internal
18021809
export const enum _VNodeFlags {
18031810
// (undocumented)

0 commit comments

Comments
 (0)