Skip to content

Commit

Permalink
move runResource to use-resource file
Browse files Browse the repository at this point in the history
  • Loading branch information
Varixo committed Jun 23, 2024
1 parent e7f732b commit 8aad31a
Show file tree
Hide file tree
Showing 11 changed files with 275 additions and 275 deletions.
12 changes: 6 additions & 6 deletions packages/docs/src/routes/api/qwik/api.json
Original file line number Diff line number Diff line change
Expand Up @@ -2335,7 +2335,7 @@
],
"kind": "Interface",
"content": "```typescript\nexport interface ResourceCtx<T> \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[previous](#)\n\n\n</td><td>\n\n`readonly`\n\n\n</td><td>\n\nT \\| undefined\n\n\n</td><td>\n\n\n</td></tr>\n<tr><td>\n\n[track](#)\n\n\n</td><td>\n\n`readonly`\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[cache(policyOrMilliseconds)](#resourcectx-cache)\n\n\n</td><td>\n\n\n</td></tr>\n<tr><td>\n\n[cleanup(callback)](#)\n\n\n</td><td>\n\n\n</td></tr>\n</tbody></table>",
"editUrl": "https://github.com/QwikDev/qwik/tree/main/packages/qwik/src/core/use/use-task.ts",
"editUrl": "https://github.com/QwikDev/qwik/tree/main/packages/qwik/src/core/use/use-resource.ts",
"mdFile": "qwik.resourcectx.md"
},
{
Expand All @@ -2349,7 +2349,7 @@
],
"kind": "TypeAlias",
"content": "```typescript\nexport type ResourceFn<T> = (ctx: ResourceCtx<unknown>) => ValueOrPromise<T>;\n```\n**References:** [ResourceCtx](#resourcectx)<!-- -->, [ValueOrPromise](#valueorpromise)",
"editUrl": "https://github.com/QwikDev/qwik/tree/main/packages/qwik/src/core/use/use-task.ts",
"editUrl": "https://github.com/QwikDev/qwik/tree/main/packages/qwik/src/core/use/use-resource.ts",
"mdFile": "qwik.resourcefn.md"
},
{
Expand Down Expand Up @@ -2377,7 +2377,7 @@
],
"kind": "Interface",
"content": "```typescript\nexport interface ResourcePending<T> \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[loading](#)\n\n\n</td><td>\n\n`readonly`\n\n\n</td><td>\n\nboolean\n\n\n</td><td>\n\n\n</td></tr>\n<tr><td>\n\n[value](#)\n\n\n</td><td>\n\n`readonly`\n\n\n</td><td>\n\nPromise&lt;T&gt;\n\n\n</td><td>\n\n\n</td></tr>\n</tbody></table>",
"editUrl": "https://github.com/QwikDev/qwik/tree/main/packages/qwik/src/core/use/use-task.ts",
"editUrl": "https://github.com/QwikDev/qwik/tree/main/packages/qwik/src/core/use/use-resource.ts",
"mdFile": "qwik.resourcepending.md"
},
{
Expand Down Expand Up @@ -2405,7 +2405,7 @@
],
"kind": "Interface",
"content": "```typescript\nexport interface ResourceRejected<T> \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[loading](#)\n\n\n</td><td>\n\n`readonly`\n\n\n</td><td>\n\nboolean\n\n\n</td><td>\n\n\n</td></tr>\n<tr><td>\n\n[value](#)\n\n\n</td><td>\n\n`readonly`\n\n\n</td><td>\n\nPromise&lt;T&gt;\n\n\n</td><td>\n\n\n</td></tr>\n</tbody></table>",
"editUrl": "https://github.com/QwikDev/qwik/tree/main/packages/qwik/src/core/use/use-task.ts",
"editUrl": "https://github.com/QwikDev/qwik/tree/main/packages/qwik/src/core/use/use-resource.ts",
"mdFile": "qwik.resourcerejected.md"
},
{
Expand All @@ -2419,7 +2419,7 @@
],
"kind": "Interface",
"content": "```typescript\nexport interface ResourceResolved<T> \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[loading](#)\n\n\n</td><td>\n\n`readonly`\n\n\n</td><td>\n\nboolean\n\n\n</td><td>\n\n\n</td></tr>\n<tr><td>\n\n[value](#)\n\n\n</td><td>\n\n`readonly`\n\n\n</td><td>\n\nPromise&lt;T&gt;\n\n\n</td><td>\n\n\n</td></tr>\n</tbody></table>",
"editUrl": "https://github.com/QwikDev/qwik/tree/main/packages/qwik/src/core/use/use-task.ts",
"editUrl": "https://github.com/QwikDev/qwik/tree/main/packages/qwik/src/core/use/use-resource.ts",
"mdFile": "qwik.resourceresolved.md"
},
{
Expand All @@ -2433,7 +2433,7 @@
],
"kind": "TypeAlias",
"content": "```typescript\nexport type ResourceReturn<T> = ResourcePending<T> | ResourceResolved<T> | ResourceRejected<T>;\n```\n**References:** [ResourcePending](#resourcepending)<!-- -->, [ResourceResolved](#resourceresolved)<!-- -->, [ResourceRejected](#resourcerejected)",
"editUrl": "https://github.com/QwikDev/qwik/tree/main/packages/qwik/src/core/use/use-task.ts",
"editUrl": "https://github.com/QwikDev/qwik/tree/main/packages/qwik/src/core/use/use-resource.ts",
"mdFile": "qwik.resourcereturn.md"
},
{
Expand Down
12 changes: 6 additions & 6 deletions packages/docs/src/routes/api/qwik/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -4849,7 +4849,7 @@ Description
</td></tr>
</tbody></table>
[Edit this section](https://github.com/QwikDev/qwik/tree/main/packages/qwik/src/core/use/use-task.ts)
[Edit this section](https://github.com/QwikDev/qwik/tree/main/packages/qwik/src/core/use/use-resource.ts)
## ResourceFn
Expand All @@ -4859,7 +4859,7 @@ export type ResourceFn<T> = (ctx: ResourceCtx<unknown>) => ValueOrPromise<T>;
**References:** [ResourceCtx](#resourcectx), [ValueOrPromise](#valueorpromise)
[Edit this section](https://github.com/QwikDev/qwik/tree/main/packages/qwik/src/core/use/use-task.ts)
[Edit this section](https://github.com/QwikDev/qwik/tree/main/packages/qwik/src/core/use/use-resource.ts)
## ResourceOptions
Expand Down Expand Up @@ -4960,7 +4960,7 @@ Promise&lt;T&gt;
</td></tr>
</tbody></table>
[Edit this section](https://github.com/QwikDev/qwik/tree/main/packages/qwik/src/core/use/use-task.ts)
[Edit this section](https://github.com/QwikDev/qwik/tree/main/packages/qwik/src/core/use/use-resource.ts)
## ResourceProps
Expand Down Expand Up @@ -5102,7 +5102,7 @@ Promise&lt;T&gt;
</td></tr>
</tbody></table>
[Edit this section](https://github.com/QwikDev/qwik/tree/main/packages/qwik/src/core/use/use-task.ts)
[Edit this section](https://github.com/QwikDev/qwik/tree/main/packages/qwik/src/core/use/use-resource.ts)
## ResourceResolved
Expand Down Expand Up @@ -5159,7 +5159,7 @@ Promise&lt;T&gt;
</td></tr>
</tbody></table>
[Edit this section](https://github.com/QwikDev/qwik/tree/main/packages/qwik/src/core/use/use-task.ts)
[Edit this section](https://github.com/QwikDev/qwik/tree/main/packages/qwik/src/core/use/use-resource.ts)
## ResourceReturn
Expand All @@ -5172,7 +5172,7 @@ export type ResourceReturn<T> =
**References:** [ResourcePending](#resourcepending), [ResourceResolved](#resourceresolved), [ResourceRejected](#resourcerejected)
[Edit this section](https://github.com/QwikDev/qwik/tree/main/packages/qwik/src/core/use/use-task.ts)
[Edit this section](https://github.com/QwikDev/qwik/tree/main/packages/qwik/src/core/use/use-resource.ts)
## ScriptHTMLAttributes
Expand Down
3 changes: 2 additions & 1 deletion packages/qwik/src/core/container/container.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { qError, QError_invalidRefValue } from '../error/error';
import type { ResourceReturnInternal, SubscriberEffect } from '../use/use-task';
import type { SubscriberEffect } from '../use/use-task';
import { seal } from '../util/qdev';
import { isFunction } from '../util/types';
import type { QRL } from '../qrl/qrl.public';
Expand All @@ -12,6 +12,7 @@ import { directGetAttribute } from '../render/fast-calls';
import type { QContext } from '../state/context';
import { isServerPlatform } from '../platform/platform';
import type { StoreTracker } from '../state/store';
import type { ResourceReturnInternal } from '../use/use-resource';

export type GetObject = (id: string) => any;
// v2 allows numbers
Expand Down
8 changes: 2 additions & 6 deletions packages/qwik/src/core/container/pause.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,7 @@ import { HOST_FLAG_DYNAMIC, tryGetContext, type QContext } from '../state/contex
import { groupListeners } from '../state/listeners';
import { SignalImpl } from '../state/signal';
import { serializeSStyle } from '../style/qrl-styles';
import {
TaskFlags,
cleanupTask,
isResourceTask,
type ResourceReturnInternal,
} from '../use/use-task';
import { TaskFlags, cleanupTask } from '../use/use-task';
import { isNotNullable, isPromise } from '../util/promises';
import { isArray, isObject, isSerializableObject } from '../util/types';
import {
Expand All @@ -68,6 +63,7 @@ import {
} from './container';
import { UNDEFINED_PREFIX, collectDeps, serializeValue } from './serializers';
import { isQrl } from '../qrl/qrl-class';
import { isResourceTask, type ResourceReturnInternal } from '../use/use-resource';

/** @internal */
export const _serializeData = async (data: any, pureQRL?: boolean) => {
Expand Down
8 changes: 6 additions & 2 deletions packages/qwik/src/core/container/serializers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,15 @@ import {
import { parseQRL, serializeQRL } from '../qrl/qrl';
import { isQrl, type QRLInternal } from '../qrl/qrl-class';
import { intToStr, type ContainerState, type GetObject, type MustGetObjID } from './container';
import { isResourceReturn, parseResourceReturn, serializeResource } from '../use/use-resource';
import {
isResourceReturn,
parseResourceReturn,
serializeResource,
type ResourceReturnInternal,
} from '../use/use-resource';
import {
isSubscriberDescriptor,
parseTask,
type ResourceReturnInternal,
serializeTask,
type SubscriberEffect,
} from '../use/use-task';
Expand Down
14 changes: 8 additions & 6 deletions packages/qwik/src/core/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,18 +107,20 @@ export type {
ComputedFn,
EagernessOptions,
OnVisibleTaskOptions,
ResourceCtx,
ResourceFn,
ResourcePending,
ResourceRejected,
ResourceResolved,
ResourceReturn,
TaskCtx,
TaskFn,
Tracker,
UseTaskOptions,
VisibleTaskStrategy,
} from './use/use-task';
export type {
ResourceCtx,
ResourceFn,
ResourcePending,
ResourceRejected,
ResourceResolved,
ResourceReturn,
} from './use/use-resource';
export type { ResourceProps, ResourceOptions } from './use/use-resource';
export { useResource$, useResourceQrl, Resource } from './use/use-resource';
export { useTask$, useTaskQrl } from './use/use-task';
Expand Down
2 changes: 1 addition & 1 deletion packages/qwik/src/core/state/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ import { notifyChange } from '../render/dom/notify-render';
import type { QwikElement } from '../render/dom/virtual-element';
import { serializeAttribute } from '../render/execute-component';
import { trackSignal } from '../use/use-core';
import { isResourceTask } from '../use/use-resource';
import {
TaskFlags,
isComputedTask,
isResourceTask,
isSubscriberDescriptor,
isTask,
type SubscriberEffect,
Expand Down
Loading

0 comments on commit 8aad31a

Please sign in to comment.