@tanstack/angular-query 5.0.0-rc.4 → 5.0.0-rc.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/hydration-state-key.mjs +10 -13
- package/hydration-state-key.mjs.map +1 -1
- package/index.mjs +8 -20
- package/index.mjs.map +1 -1
- package/infinite-query-options.d.ts +7 -18
- package/infinite-query-options.mjs +6 -5
- package/infinite-query-options.mjs.map +1 -1
- package/inject-base-query.d.ts +3 -0
- package/inject-base-query.mjs +62 -58
- package/inject-base-query.mjs.map +1 -1
- package/inject-infinite-query.d.ts +7 -11
- package/inject-infinite-query.mjs +16 -32
- package/inject-infinite-query.mjs.map +1 -1
- package/inject-is-fetching.d.ts +1 -1
- package/inject-is-fetching.mjs +22 -15
- package/inject-is-fetching.mjs.map +1 -1
- package/inject-is-mutating.d.ts +1 -1
- package/inject-is-mutating.mjs +22 -15
- package/inject-is-mutating.mjs.map +1 -1
- package/inject-is-restoring.d.ts +2 -0
- package/inject-is-restoring.mjs +28 -17
- package/inject-is-restoring.mjs.map +1 -1
- package/inject-mutation-state.d.ts +9 -0
- package/inject-mutation-state.mjs +25 -23
- package/inject-mutation-state.mjs.map +1 -1
- package/inject-mutation.d.ts +2 -4
- package/inject-mutation.mjs +87 -67
- package/inject-mutation.mjs.map +1 -1
- package/inject-queries.d.ts +1 -3
- package/inject-queries.mjs +122 -114
- package/inject-queries.mjs.map +1 -1
- package/inject-queries.types.d.ts +15 -0
- package/inject-query.d.ts +7 -13
- package/inject-query.mjs +11 -14
- package/inject-query.mjs.map +1 -1
- package/internal.mjs +2 -7
- package/mutation-options.d.ts +2 -6
- package/mutation-options.mjs +6 -5
- package/mutation-options.mjs.map +1 -1
- package/package.json +2 -2
- package/providers.d.ts +16 -14
- package/providers.mjs +138 -75
- package/providers.mjs.map +1 -1
- package/query-options.d.ts +6 -16
- package/query-options.mjs +6 -5
- package/query-options.mjs.map +1 -1
- package/query-resource.d.ts +4 -3
- package/query-resource.mjs +72 -63
- package/query-resource.mjs.map +1 -1
- package/schematics/migrate-from-experimental/index.js +2 -2
- package/schematics/ng-add/index.js +1 -1
- package/types.d.ts +70 -10
- package/utils/inject-external-store.d.ts +3 -0
- package/utils/inject-external-store.mjs +54 -38
- package/utils/inject-external-store.mjs.map +1 -1
- package/utils/inject-pending-tasks-lifecycle.d.ts +13 -1
- package/utils/inject-pending-tasks-lifecycle.mjs +32 -29
- package/utils/inject-pending-tasks-lifecycle.mjs.map +1 -1
- package/utils/inject-query-zone.d.ts +4 -1
- package/utils/inject-query-zone.mjs +12 -7
- package/utils/inject-query-zone.mjs.map +1 -1
- package/utils/resource-types.d.ts +3 -0
- package/utils/result-fields.d.ts +9 -0
- package/utils/result-fields.mjs +55 -62
- package/utils/result-fields.mjs.map +1 -1
- package/utils/signal-proxy.d.ts +6 -0
- package/utils/signal-proxy.mjs +16 -9
- package/utils/signal-proxy.mjs.map +1 -1
- package/internal.mjs.map +0 -1
package/query-resource.mjs
CHANGED
|
@@ -1,70 +1,79 @@
|
|
|
1
1
|
import { computed, untracked } from "@angular/core";
|
|
2
|
+
//#region src/query-resource.ts
|
|
3
|
+
/**
|
|
4
|
+
* Converts an Angular Query result into Angular's Resource interface.
|
|
5
|
+
*
|
|
6
|
+
* Call this function once and reuse the returned resource.
|
|
7
|
+
* @param query - An Angular Query or infinite-query result.
|
|
8
|
+
* @returns A Resource-compatible view of the query result.
|
|
9
|
+
*/
|
|
2
10
|
function toResource(query) {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
if (!untracked(query.isStale)) {
|
|
51
|
-
return false;
|
|
52
|
-
}
|
|
53
|
-
void query.refetch();
|
|
54
|
-
return true;
|
|
55
|
-
}
|
|
56
|
-
};
|
|
11
|
+
const status = computed(() => {
|
|
12
|
+
const fetchStatus = query.fetchStatus();
|
|
13
|
+
const data = query.data();
|
|
14
|
+
if (fetchStatus === "fetching" || fetchStatus === "paused") return data === void 0 ? "loading" : "reloading";
|
|
15
|
+
switch (query.status()) {
|
|
16
|
+
case "success": return "resolved";
|
|
17
|
+
case "error": return "error";
|
|
18
|
+
case "pending": return "idle";
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
const error = computed(() => {
|
|
22
|
+
return query.status() === "error" ? normalizeError(query.error()) : void 0;
|
|
23
|
+
});
|
|
24
|
+
const value = computed(() => {
|
|
25
|
+
if (status() === "error") throw error();
|
|
26
|
+
return query.data();
|
|
27
|
+
});
|
|
28
|
+
const snapshot = computed(() => {
|
|
29
|
+
const currentStatus = status();
|
|
30
|
+
if (currentStatus === "error") return {
|
|
31
|
+
status: "error",
|
|
32
|
+
error: error()
|
|
33
|
+
};
|
|
34
|
+
return {
|
|
35
|
+
status: currentStatus,
|
|
36
|
+
value: query.data()
|
|
37
|
+
};
|
|
38
|
+
});
|
|
39
|
+
const hasValue = (() => status() !== "error" && query.data() !== void 0);
|
|
40
|
+
return {
|
|
41
|
+
value,
|
|
42
|
+
status,
|
|
43
|
+
error,
|
|
44
|
+
snapshot,
|
|
45
|
+
isLoading: computed(() => {
|
|
46
|
+
const currentStatus = status();
|
|
47
|
+
return currentStatus === "loading" || currentStatus === "reloading";
|
|
48
|
+
}),
|
|
49
|
+
hasValue,
|
|
50
|
+
reload() {
|
|
51
|
+
const currentStatus = untracked(status);
|
|
52
|
+
if (currentStatus === "idle" || currentStatus === "loading" || currentStatus === "reloading") return false;
|
|
53
|
+
if (!untracked(query.isStale)) return false;
|
|
54
|
+
query.refetch();
|
|
55
|
+
return true;
|
|
56
|
+
}
|
|
57
|
+
};
|
|
57
58
|
}
|
|
59
|
+
/**
|
|
60
|
+
* Converts an unknown rejection reason to an Error-compatible value.
|
|
61
|
+
* @param error - The rejected value.
|
|
62
|
+
* @returns The existing error-like value, or an Error wrapping the rejection.
|
|
63
|
+
*/
|
|
58
64
|
function normalizeError(error) {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
}
|
|
62
|
-
return new Error(String(error), { cause: error });
|
|
65
|
+
if (isErrorLike(error)) return error;
|
|
66
|
+
return new Error(String(error), { cause: error });
|
|
63
67
|
}
|
|
68
|
+
/**
|
|
69
|
+
* Checks whether a value provides the name and message of an Error.
|
|
70
|
+
* @param error - The value to inspect.
|
|
71
|
+
* @returns Whether the value can be used as an Error.
|
|
72
|
+
*/
|
|
64
73
|
function isErrorLike(error) {
|
|
65
|
-
|
|
74
|
+
return error instanceof Error || typeof error === "object" && error !== null && typeof error.name === "string" && typeof error.message === "string";
|
|
66
75
|
}
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
//# sourceMappingURL=query-resource.mjs.map
|
|
76
|
+
//#endregion
|
|
77
|
+
export { toResource };
|
|
78
|
+
|
|
79
|
+
//# sourceMappingURL=query-resource.mjs.map
|
package/query-resource.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"query-resource.mjs","sources":["../src/query-resource.ts"],"sourcesContent":["import { computed, untracked } from '@angular/core'\nimport type { QueryObserverResult } from '@tanstack/query-core'\nimport type { ResourceSnapshot } from './utils/resource-types'\nimport type { Resource, ResourceStatus, Signal } from '@angular/core'\n\nexport interface QueryResource<TValue> extends Resource<TValue> {\n /**\n * The current query state as a single snapshot.\n */\n readonly snapshot: Signal<ResourceSnapshot<TValue>>\n\n /**\n * Requests a new query fetch only when the current query data is stale.\n *\n * Used for compatibility with Angular APIs that might want to reload a resource,\n * like Signal Forms' validateAsync resource interface.\n
|
|
1
|
+
{"version":3,"file":"query-resource.mjs","names":[],"sources":["../src/query-resource.ts"],"sourcesContent":["import { computed, untracked } from '@angular/core'\nimport type { QueryObserverResult } from '@tanstack/query-core'\nimport type { ResourceSnapshot } from './utils/resource-types'\nimport type { Resource, ResourceStatus, Signal } from '@angular/core'\n\n/**\n * A query-backed Angular Resource that also exposes an atomic state snapshot.\n */\nexport interface QueryResource<TValue> extends Resource<TValue> {\n /**\n * The current query state as a single snapshot.\n */\n readonly snapshot: Signal<ResourceSnapshot<TValue>>\n\n /**\n * Requests a new query fetch only when the current query data is stale.\n *\n * Used for compatibility with Angular APIs that might want to reload a resource,\n * like Signal Forms' validateAsync resource interface.\n * @returns `true` if a reload was initiated, `false` if a reload was unnecessary or unsupported.\n */\n reload: () => boolean\n}\n\ntype QueryResourceSource<TValue> = {\n readonly data: Signal<TValue>\n readonly status: Signal<QueryObserverResult['status']>\n readonly fetchStatus: Signal<QueryObserverResult['fetchStatus']>\n readonly error: Signal<unknown>\n readonly isStale: Signal<boolean>\n readonly refetch: () => unknown\n}\n\n/**\n * Converts an Angular Query result into Angular's Resource interface.\n *\n * Call this function once and reuse the returned resource.\n * @param query - An Angular Query or infinite-query result.\n * @returns A Resource-compatible view of the query result.\n */\nexport function toResource<TValue>(\n query: QueryResourceSource<TValue>,\n): QueryResource<TValue> {\n // Intentionally does not use resource from snapshot to have\n // support for the reload method for compatible libraries\n const status = computed<ResourceStatus>(() => {\n const fetchStatus = query.fetchStatus()\n const data = query.data()\n\n if (fetchStatus === 'fetching' || fetchStatus === 'paused') {\n return data === undefined ? 'loading' : 'reloading'\n }\n\n switch (query.status()) {\n case 'success':\n return 'resolved'\n case 'error':\n return 'error'\n case 'pending':\n return 'idle'\n }\n })\n\n const error = computed<Error | undefined>(() => {\n return query.status() === 'error'\n ? normalizeError(query.error())\n : undefined\n })\n\n const value = computed(() => {\n if (status() === 'error') {\n throw error()\n }\n\n return query.data()\n })\n\n const snapshot = computed<ResourceSnapshot<TValue>>(() => {\n const currentStatus = status()\n\n if (currentStatus === 'error') {\n return { status: 'error', error: error()! }\n }\n\n return { status: currentStatus, value: query.data() }\n })\n\n const hasValue = (() =>\n status() !== 'error' &&\n query.data() !== undefined) as QueryResource<TValue>['hasValue']\n\n return {\n value,\n status,\n error,\n snapshot,\n isLoading: computed(() => {\n const currentStatus = status()\n return currentStatus === 'loading' || currentStatus === 'reloading'\n }),\n hasValue,\n reload(): boolean {\n const currentStatus = untracked(status)\n if (\n currentStatus === 'idle' ||\n currentStatus === 'loading' ||\n currentStatus === 'reloading'\n ) {\n return false\n }\n\n if (!untracked(query.isStale)) {\n return false\n }\n\n void query.refetch()\n return true\n },\n }\n}\n\n/**\n * Converts an unknown rejection reason to an Error-compatible value.\n * @param error - The rejected value.\n * @returns The existing error-like value, or an Error wrapping the rejection.\n */\nfunction normalizeError(error: unknown): Error {\n if (isErrorLike(error)) {\n return error\n }\n\n return new Error(String(error), { cause: error })\n}\n\n/**\n * Checks whether a value provides the name and message of an Error.\n * @param error - The value to inspect.\n * @returns Whether the value can be used as an Error.\n */\nfunction isErrorLike(error: unknown): error is Error {\n return (\n error instanceof Error ||\n (typeof error === 'object' &&\n error !== null &&\n typeof (error as Error).name === 'string' &&\n typeof (error as Error).message === 'string')\n )\n}\n"],"mappings":";;;;;;;;;AAwCA,SAAgB,WACd,OACuB;CAGvB,MAAM,SAAS,eAA+B;EAC5C,MAAM,cAAc,MAAM,YAAY;EACtC,MAAM,OAAO,MAAM,KAAK;EAExB,IAAI,gBAAgB,cAAc,gBAAgB,UAChD,OAAO,SAAS,KAAA,IAAY,YAAY;EAG1C,QAAQ,MAAM,OAAO,GAArB;GACE,KAAK,WACH,OAAO;GACT,KAAK,SACH,OAAO;GACT,KAAK,WACH,OAAO;EACX;CACF,CAAC;CAED,MAAM,QAAQ,eAAkC;EAC9C,OAAO,MAAM,OAAO,MAAM,UACtB,eAAe,MAAM,MAAM,CAAC,IAC5B,KAAA;CACN,CAAC;CAED,MAAM,QAAQ,eAAe;EAC3B,IAAI,OAAO,MAAM,SACf,MAAM,MAAM;EAGd,OAAO,MAAM,KAAK;CACpB,CAAC;CAED,MAAM,WAAW,eAAyC;EACxD,MAAM,gBAAgB,OAAO;EAE7B,IAAI,kBAAkB,SACpB,OAAO;GAAE,QAAQ;GAAS,OAAO,MAAM;EAAG;EAG5C,OAAO;GAAE,QAAQ;GAAe,OAAO,MAAM,KAAK;EAAE;CACtD,CAAC;CAED,MAAM,kBACJ,OAAO,MAAM,WACb,MAAM,KAAK,MAAM,KAAA;CAEnB,OAAO;EACL;EACA;EACA;EACA;EACA,WAAW,eAAe;GACxB,MAAM,gBAAgB,OAAO;GAC7B,OAAO,kBAAkB,aAAa,kBAAkB;EAC1D,CAAC;EACD;EACA,SAAkB;GAChB,MAAM,gBAAgB,UAAU,MAAM;GACtC,IACE,kBAAkB,UAClB,kBAAkB,aAClB,kBAAkB,aAElB,OAAO;GAGT,IAAI,CAAC,UAAU,MAAM,OAAO,GAC1B,OAAO;GAGT,MAAW,QAAQ;GACnB,OAAO;EACT;CACF;AACF;;;;;;AAOA,SAAS,eAAe,OAAuB;CAC7C,IAAI,YAAY,KAAK,GACnB,OAAO;CAGT,OAAO,IAAI,MAAM,OAAO,KAAK,GAAG,EAAE,OAAO,MAAM,CAAC;AAClD;;;;;;AAOA,SAAS,YAAY,OAAgC;CACnD,OACE,iBAAiB,SAChB,OAAO,UAAU,YAChB,UAAU,QACV,OAAQ,MAAgB,SAAS,YACjC,OAAQ,MAAgB,YAAY;AAE1C"}
|
|
@@ -6,9 +6,9 @@ const tasks_1 = require("@angular-devkit/schematics/tasks");
|
|
|
6
6
|
const source_1 = require("./source");
|
|
7
7
|
const workspace_1 = require("./workspace");
|
|
8
8
|
const PACKAGE_NAME = '@tanstack/angular-query';
|
|
9
|
-
const PACKAGE_VERSION = '5.0.0-rc.
|
|
9
|
+
const PACKAGE_VERSION = '5.0.0-rc.5';
|
|
10
10
|
const DEVTOOLS_PACKAGE_NAME = '@tanstack/angular-query-devtools';
|
|
11
|
-
const DEVTOOLS_PACKAGE_VERSION = '5.0.0-rc.
|
|
11
|
+
const DEVTOOLS_PACKAGE_VERSION = '5.0.0-rc.5';
|
|
12
12
|
const MIGRATION_GUIDE = 'https://tanstack.com/query/latest/docs/framework/angular/guides/migrating-from-experimental';
|
|
13
13
|
const dependencyTypes = [
|
|
14
14
|
dependencies_1.NodeDependencyType.Default,
|
|
@@ -16,7 +16,7 @@ const typescript_1 = __importDefault(require("typescript"));
|
|
|
16
16
|
// The published schematic contains literal values and does not read package.json.
|
|
17
17
|
const PACKAGE_NAME = '@tanstack/angular-query';
|
|
18
18
|
const DEVTOOLS_PACKAGE_NAME = '@tanstack/angular-query-devtools';
|
|
19
|
-
const DEVTOOLS_PACKAGE_VERSION = '5.0.0-rc.
|
|
19
|
+
const DEVTOOLS_PACKAGE_VERSION = '5.0.0-rc.5';
|
|
20
20
|
function hasPackageDependency(tree, name) {
|
|
21
21
|
const packageJsonPath = tree.exists('/package.json')
|
|
22
22
|
? '/package.json'
|
package/types.d.ts
CHANGED
|
@@ -3,6 +3,10 @@ import { Signal } from '@angular/core';
|
|
|
3
3
|
import { MapToSignals } from './utils/signal-proxy.js';
|
|
4
4
|
import { InfiniteQueryResultFields, MutationResultFields, QueryResultFields } from './utils/result-fields.js';
|
|
5
5
|
type SignalFunction<T extends () => any> = T & Signal<ReturnType<T>>;
|
|
6
|
+
/**
|
|
7
|
+
* Options accepted by `injectQuery`, with cache data projected through an optional `select`.
|
|
8
|
+
* Angular owns result notifications and exposes errors through signals rather than error boundaries.
|
|
9
|
+
*/
|
|
6
10
|
export type CreateQueryOptions<TQueryFnData = unknown, TError = DefaultError, TData = TQueryFnData, TQueryKey extends QueryKey = QueryKey> = OmitKeyof<QueryObserverOptions<TQueryFnData, TError, TData, TQueryFnData, TQueryKey>, 'notifyOnChangeProps' | 'suspense' | 'throwOnError'>;
|
|
7
11
|
type CreateStatusBasedQueryResult<TStatus extends QueryObserverResult['status'], TData = unknown, TError = DefaultError> = Extract<QueryObserverResult<TData, TError>, {
|
|
8
12
|
status: TStatus;
|
|
@@ -16,26 +20,77 @@ type CreateStatusBasedInfiniteQueryResult<TStatus extends InfiniteQueryObserverR
|
|
|
16
20
|
type CreateStatusBasedDefinedInfiniteQueryResult<TStatus extends DefinedInfiniteQueryObserverResult['status'], TData = unknown, TError = DefaultError> = Extract<DefinedInfiniteQueryObserverResult<TData, TError>, {
|
|
17
21
|
status: TStatus;
|
|
18
22
|
}>;
|
|
23
|
+
/**
|
|
24
|
+
* Signal-backed guards that narrow a query result and its data and error fields by status.
|
|
25
|
+
*/
|
|
19
26
|
export interface BaseQueryNarrowing<TData = unknown, TError = DefaultError> {
|
|
27
|
+
/**
|
|
28
|
+
* Returns whether the result is successful and narrows its data and error signals.
|
|
29
|
+
*/
|
|
20
30
|
isSuccess: SignalFunction<() => this is CreateBaseQueryResult<TData, TError, CreateStatusBasedQueryResult<'success', TData, TError>>>;
|
|
31
|
+
/**
|
|
32
|
+
* Returns whether the result failed and narrows its data and error signals.
|
|
33
|
+
*/
|
|
21
34
|
isError: SignalFunction<() => this is CreateBaseQueryResult<TData, TError, CreateStatusBasedQueryResult<'error', TData, TError>>>;
|
|
35
|
+
/**
|
|
36
|
+
* Narrows the result to the pending state when that state is possible.
|
|
37
|
+
*/
|
|
22
38
|
isPending: SignalFunction<() => this is CreateBaseQueryResult<TData, TError, CreateStatusBasedQueryResult<'pending', TData, TError>>>;
|
|
23
39
|
}
|
|
40
|
+
/**
|
|
41
|
+
* Signal-backed guards for a query whose initial data excludes the pending state.
|
|
42
|
+
*/
|
|
24
43
|
export interface DefinedQueryNarrowing<TData = unknown, TError = DefaultError> {
|
|
44
|
+
/**
|
|
45
|
+
* Returns whether the result is successful and narrows its data and error signals.
|
|
46
|
+
*/
|
|
25
47
|
isSuccess: SignalFunction<() => this is DefinedCreateQueryResult<TData, TError, CreateStatusBasedDefinedQueryResult<'success', TData, TError>>>;
|
|
48
|
+
/**
|
|
49
|
+
* Returns whether the result failed and narrows its data and error signals.
|
|
50
|
+
*/
|
|
26
51
|
isError: SignalFunction<() => this is DefinedCreateQueryResult<TData, TError, CreateStatusBasedDefinedQueryResult<'error', TData, TError>>>;
|
|
52
|
+
/**
|
|
53
|
+
* Narrows the result to the pending state when that state is possible.
|
|
54
|
+
*/
|
|
27
55
|
isPending: SignalFunction<() => this is never>;
|
|
28
56
|
}
|
|
57
|
+
/**
|
|
58
|
+
* Signal-backed guards that narrow a paginated query result by its current status.
|
|
59
|
+
*/
|
|
29
60
|
export interface BaseInfiniteQueryNarrowing<TData = unknown, TError = DefaultError> {
|
|
61
|
+
/**
|
|
62
|
+
* Returns whether the result is successful and narrows its data and error signals.
|
|
63
|
+
*/
|
|
30
64
|
isSuccess: SignalFunction<(this: CreateInfiniteQueryResult<TData, TError>) => this is CreateInfiniteQueryResult<TData, TError, CreateStatusBasedInfiniteQueryResult<'success', TData, TError>>>;
|
|
65
|
+
/**
|
|
66
|
+
* Returns whether the result failed and narrows its data and error signals.
|
|
67
|
+
*/
|
|
31
68
|
isError: SignalFunction<(this: CreateInfiniteQueryResult<TData, TError>) => this is CreateInfiniteQueryResult<TData, TError, CreateStatusBasedInfiniteQueryResult<'error', TData, TError>>>;
|
|
69
|
+
/**
|
|
70
|
+
* Narrows the result to the pending state when that state is possible.
|
|
71
|
+
*/
|
|
32
72
|
isPending: SignalFunction<(this: CreateInfiniteQueryResult<TData, TError>) => this is CreateInfiniteQueryResult<TData, TError, CreateStatusBasedInfiniteQueryResult<'pending', TData, TError>>>;
|
|
33
73
|
}
|
|
74
|
+
/**
|
|
75
|
+
* Signal-backed guards for a paginated query whose initial data excludes the pending state.
|
|
76
|
+
*/
|
|
34
77
|
export interface DefinedInfiniteQueryNarrowing<TData = unknown, TError = DefaultError> {
|
|
78
|
+
/**
|
|
79
|
+
* Returns whether the result is successful and narrows its data and error signals.
|
|
80
|
+
*/
|
|
35
81
|
isSuccess: SignalFunction<(this: DefinedCreateInfiniteQueryResult<TData, TError>) => this is DefinedCreateInfiniteQueryResult<TData, TError, CreateStatusBasedDefinedInfiniteQueryResult<'success', TData, TError>>>;
|
|
82
|
+
/**
|
|
83
|
+
* Returns whether the result failed and narrows its data and error signals.
|
|
84
|
+
*/
|
|
36
85
|
isError: SignalFunction<(this: DefinedCreateInfiniteQueryResult<TData, TError>) => this is DefinedCreateInfiniteQueryResult<TData, TError, CreateStatusBasedDefinedInfiniteQueryResult<'error', TData, TError>>>;
|
|
86
|
+
/**
|
|
87
|
+
* Narrows the result to the pending state when that state is possible.
|
|
88
|
+
*/
|
|
37
89
|
isPending: SignalFunction<(this: DefinedCreateInfiniteQueryResult<TData, TError>) => this is never>;
|
|
38
90
|
}
|
|
91
|
+
/**
|
|
92
|
+
* Options accepted by `injectInfiniteQuery`, including page parameters and pagination callbacks.
|
|
93
|
+
*/
|
|
39
94
|
export interface CreateInfiniteQueryOptions<TQueryFnData = unknown, TError = DefaultError, TData = TQueryFnData, TQueryKey extends QueryKey = QueryKey, TPageParam = unknown> extends OmitKeyof<InfiniteQueryObserverOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam>, 'notifyOnChangeProps' | 'suspense' | 'throwOnError'> {
|
|
40
95
|
}
|
|
41
96
|
/**
|
|
@@ -45,14 +100,12 @@ export interface CreateInfiniteQueryOptions<TQueryFnData = unknown, TError = Def
|
|
|
45
100
|
* while function fields (like `refetch`) are called directly, unchanged. `isSuccess`/`isError`/`isPending`
|
|
46
101
|
* are {@link BaseQueryNarrowing} type-guard methods rather than plain booleans.
|
|
47
102
|
* `injectInfiniteQuery` returns {@link CreateInfiniteQueryResult} instead.
|
|
48
|
-
*
|
|
49
103
|
* @template TData - The type `data` ends up as after `select` runs.
|
|
50
104
|
* @template TError - The type of errors your `queryFn` may throw.
|
|
51
105
|
*/
|
|
52
106
|
export type CreateBaseQueryResult<TData = unknown, TError = DefaultError, TState extends QueryObserverResult<TData, TError> = QueryObserverResult<TData, TError>> = BaseQueryNarrowing<TData, TError> & MapToSignals<OmitKeyof<TState, keyof BaseQueryNarrowing, 'safely'>, QueryResultFields>;
|
|
53
107
|
/**
|
|
54
108
|
* The result of `injectQuery`. Same as {@link CreateBaseQueryResult}.
|
|
55
|
-
*
|
|
56
109
|
* @template TData - The type `data` ends up as after `select` runs.
|
|
57
110
|
* @template TError - The type of errors your `queryFn` may throw.
|
|
58
111
|
*/
|
|
@@ -61,7 +114,6 @@ export type CreateQueryResult<TData = unknown, TError = DefaultError> = CreateBa
|
|
|
61
114
|
* The result of `injectQuery` when `initialData` is set — `data` is never `undefined`. Same shape as
|
|
62
115
|
* {@link DefinedQueryObserverResult} from `@tanstack/query-core`, but value fields are exposed as a
|
|
63
116
|
* `Signal` while function fields are called directly, unchanged.
|
|
64
|
-
*
|
|
65
117
|
* @template TData - The type `data` ends up as after `select` runs.
|
|
66
118
|
* @template TError - The type of errors your `queryFn` may throw.
|
|
67
119
|
*/
|
|
@@ -71,7 +123,6 @@ export type DefinedCreateQueryResult<TData = unknown, TError = DefaultError, TSt
|
|
|
71
123
|
* query is `pending`. Same shape as {@link InfiniteQueryObserverResult} from `@tanstack/query-core`, but
|
|
72
124
|
* value fields are exposed as a `Signal` while function fields (like `fetchNextPage`) are called directly,
|
|
73
125
|
* unchanged.
|
|
74
|
-
*
|
|
75
126
|
* @template TData - The type `data` ends up as after `select` runs.
|
|
76
127
|
* @template TError - The type of errors your `queryFn` may throw.
|
|
77
128
|
*/
|
|
@@ -80,7 +131,6 @@ export type CreateInfiniteQueryResult<TData = unknown, TError = DefaultError, TS
|
|
|
80
131
|
* The result of `injectInfiniteQuery` when `initialData` is set — `data` is never `undefined`. Same shape as
|
|
81
132
|
* {@link DefinedInfiniteQueryObserverResult} from `@tanstack/query-core`, but value fields are exposed as a
|
|
82
133
|
* `Signal` while function fields are called directly, unchanged.
|
|
83
|
-
*
|
|
84
134
|
* @template TData - The type `data` ends up as after `select` runs.
|
|
85
135
|
* @template TError - The type of errors your `queryFn` may throw.
|
|
86
136
|
*/
|
|
@@ -88,7 +138,6 @@ export type DefinedCreateInfiniteQueryResult<TData = unknown, TError = DefaultEr
|
|
|
88
138
|
/**
|
|
89
139
|
* The options accepted by `injectMutation`. Same as {@link MutationObserverOptions} from
|
|
90
140
|
* `@tanstack/query-core`, minus the internal `_defaulted` flag.
|
|
91
|
-
*
|
|
92
141
|
* @template TData - The type your mutation function resolves to.
|
|
93
142
|
* @template TError - The type of errors your mutation function may throw.
|
|
94
143
|
* @template TVariables - The type of the variable passed to `mutate`/`mutateAsync`.
|
|
@@ -101,7 +150,6 @@ export interface CreateMutationOptions<TData = unknown, TError = DefaultError, T
|
|
|
101
150
|
* The type of `mutate`, as returned by `injectMutation`. Forwards the variables (and an optional per-call
|
|
102
151
|
* `onSuccess`/`onError`/`onSettled`) to the underlying `mutate` call. Fire-and-forget — errors are surfaced
|
|
103
152
|
* through the mutation result, not thrown.
|
|
104
|
-
*
|
|
105
153
|
* @template TData - The type your mutation function resolves to.
|
|
106
154
|
* @template TError - The type of errors your mutation function may throw.
|
|
107
155
|
* @template TVariables - The type of the variable passed to `mutate`.
|
|
@@ -112,7 +160,6 @@ export type CreateMutateFunction<TData = unknown, TError = DefaultError, TVariab
|
|
|
112
160
|
/**
|
|
113
161
|
* The type of `mutateAsync`, as returned by `injectMutation`. Similar to {@link CreateMutateFunction}, but
|
|
114
162
|
* returns a promise which can be awaited.
|
|
115
|
-
*
|
|
116
163
|
* @template TData - The type your mutation function resolves to.
|
|
117
164
|
* @template TError - The type of errors your mutation function may throw.
|
|
118
165
|
* @template TVariables - The type of the variable passed to `mutateAsync`.
|
|
@@ -124,7 +171,6 @@ export type CreateMutateAsyncFunction<TData = unknown, TError = DefaultError, TV
|
|
|
124
171
|
* The pre-`Signal` shape {@link CreateMutationResult} is built from — not what `injectMutation` actually
|
|
125
172
|
* returns. Same as {@link MutationObserverResult} from `@tanstack/query-core`, with `mutate` narrowed to the
|
|
126
173
|
* fire-and-forget {@link CreateMutateFunction} signature, plus the added `mutateAsync`.
|
|
127
|
-
*
|
|
128
174
|
* @template TData - The type your mutation function resolves to.
|
|
129
175
|
* @template TError - The type of errors your mutation function may throw.
|
|
130
176
|
* @template TVariables - The type of the variable passed to `mutate`/`mutateAsync`.
|
|
@@ -142,10 +188,25 @@ export type CreateBaseMutationResult<TData = unknown, TError = DefaultError, TVa
|
|
|
142
188
|
type CreateStatusBasedMutationResult<TStatus extends CreateBaseMutationResult['status'], TData = unknown, TError = DefaultError, TVariables = unknown, TOnMutateResult = unknown> = Extract<CreateBaseMutationResult<TData, TError, TVariables, TOnMutateResult>, {
|
|
143
189
|
status: TStatus;
|
|
144
190
|
}>;
|
|
191
|
+
/**
|
|
192
|
+
* Signal-backed guards that narrow mutation data, errors, and variables by the current status.
|
|
193
|
+
*/
|
|
145
194
|
export interface BaseMutationNarrowing<TData = unknown, TError = DefaultError, TVariables = unknown, TOnMutateResult = unknown> {
|
|
195
|
+
/**
|
|
196
|
+
* Whether the mutation is in the `success` state. Calling it narrows the result to that state.
|
|
197
|
+
*/
|
|
146
198
|
isSuccess: SignalFunction<(this: CreateMutationResult<TData, TError, TVariables, TOnMutateResult>) => this is CreateMutationResult<TData, TError, TVariables, TOnMutateResult, CreateStatusBasedMutationResult<'success', TData, TError, TVariables, TOnMutateResult>>>;
|
|
199
|
+
/**
|
|
200
|
+
* Whether the mutation is in the `error` state. Calling it narrows the result to that state.
|
|
201
|
+
*/
|
|
147
202
|
isError: SignalFunction<(this: CreateMutationResult<TData, TError, TVariables, TOnMutateResult>) => this is CreateMutationResult<TData, TError, TVariables, TOnMutateResult, CreateStatusBasedMutationResult<'error', TData, TError, TVariables, TOnMutateResult>>>;
|
|
203
|
+
/**
|
|
204
|
+
* Whether the mutation is in the `pending` state. Calling it narrows the result to that state.
|
|
205
|
+
*/
|
|
148
206
|
isPending: SignalFunction<(this: CreateMutationResult<TData, TError, TVariables, TOnMutateResult>) => this is CreateMutationResult<TData, TError, TVariables, TOnMutateResult, CreateStatusBasedMutationResult<'pending', TData, TError, TVariables, TOnMutateResult>>>;
|
|
207
|
+
/**
|
|
208
|
+
* Whether the mutation is in the `idle` state. Calling it narrows the result to that state.
|
|
209
|
+
*/
|
|
149
210
|
isIdle: SignalFunction<(this: CreateMutationResult<TData, TError, TVariables, TOnMutateResult>) => this is CreateMutationResult<TData, TError, TVariables, TOnMutateResult, CreateStatusBasedMutationResult<'idle', TData, TError, TVariables, TOnMutateResult>>>;
|
|
150
211
|
}
|
|
151
212
|
/**
|
|
@@ -153,7 +214,6 @@ export interface BaseMutationNarrowing<TData = unknown, TError = DefaultError, T
|
|
|
153
214
|
* a `Signal` — read them with `mutation.data()`, not `mutation.data` — while function fields (`mutate`,
|
|
154
215
|
* `mutateAsync`, `reset`) are called directly, unchanged. `isSuccess`/`isError`/`isPending`/`isIdle` are
|
|
155
216
|
* {@link BaseMutationNarrowing} type-guard methods rather than plain booleans.
|
|
156
|
-
*
|
|
157
217
|
* @template TData - The type your mutation function resolves to.
|
|
158
218
|
* @template TError - The type of errors your mutation function may throw.
|
|
159
219
|
* @template TVariables - The type of the variable passed to `mutate`/`mutateAsync`.
|
|
@@ -28,6 +28,9 @@ interface ExternalStoreOptions<T> {
|
|
|
28
28
|
* errors follow Angular's normal effect error handling; the helper does not store
|
|
29
29
|
* them or implement retries. Destruction stops observation without changing the
|
|
30
30
|
* cached snapshot.
|
|
31
|
+
* @param binding - Produces the current snapshot reader and optional subscription.
|
|
32
|
+
* @param options - Optional equality comparison for snapshots.
|
|
33
|
+
* @returns A readonly signal containing the latest external snapshot.
|
|
31
34
|
*/
|
|
32
35
|
export declare function injectExternalStore<T>(binding: () => ExternalBinding<T>, options?: ExternalStoreOptions<T>): Signal<T>;
|
|
33
36
|
export {};
|
|
@@ -1,41 +1,57 @@
|
|
|
1
|
-
import { assertInInjectionContext, inject, DestroyRef, signal, computed, effect, untracked } from "@angular/core";
|
|
2
1
|
import { injectQueryZone } from "./inject-query-zone.mjs";
|
|
2
|
+
import { DestroyRef, assertInInjectionContext, computed, effect, inject, signal, untracked } from "@angular/core";
|
|
3
|
+
//#region src/utils/inject-external-store.ts
|
|
4
|
+
/**
|
|
5
|
+
* Creates a readonly Angular signal backed by a synchronous external store.
|
|
6
|
+
*
|
|
7
|
+
* Store access, subscription setup, and cleanup run outside NgZone so background
|
|
8
|
+
* timers do not hold Angular stability open.
|
|
9
|
+
*
|
|
10
|
+
* Reads evaluate snapshots without subscribing. An effect owns the subscription
|
|
11
|
+
* and invalidates the snapshot after setup, closing the gap between an early
|
|
12
|
+
* read and connection. The next read recomputes the snapshot; equality prevents
|
|
13
|
+
* unchanged values from propagating. Unread snapshots stay lazy.
|
|
14
|
+
*
|
|
15
|
+
* Notifications invalidate snapshots synchronously once connected. Snapshot-only
|
|
16
|
+
* dependencies do not reinstall the subscription. Subscription setup and cleanup
|
|
17
|
+
* may read the returned signal; factories and snapshot readers must not recurse.
|
|
18
|
+
*
|
|
19
|
+
* Only factory/snapshot errors are exposed on reads. Subscription and cleanup
|
|
20
|
+
* errors follow Angular's normal effect error handling; the helper does not store
|
|
21
|
+
* them or implement retries. Destruction stops observation without changing the
|
|
22
|
+
* cached snapshot.
|
|
23
|
+
* @param binding - Produces the current snapshot reader and optional subscription.
|
|
24
|
+
* @param options - Optional equality comparison for snapshots.
|
|
25
|
+
* @returns A readonly signal containing the latest external snapshot.
|
|
26
|
+
*/
|
|
3
27
|
function injectExternalStore(binding, options) {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
});
|
|
30
|
-
return computed(
|
|
31
|
-
() => {
|
|
32
|
-
revision();
|
|
33
|
-
return outsideZone(() => requested().getSnapshot());
|
|
34
|
-
},
|
|
35
|
-
(options == null ? void 0 : options.equal) ? { equal: options.equal } : void 0
|
|
36
|
-
);
|
|
28
|
+
if (typeof ngDevMode === "undefined" || ngDevMode) assertInInjectionContext(injectExternalStore);
|
|
29
|
+
const owner = inject(DestroyRef);
|
|
30
|
+
const outsideZone = injectQueryZone();
|
|
31
|
+
const revision = signal(0);
|
|
32
|
+
const requested = computed(() => outsideZone(binding));
|
|
33
|
+
const invalidate = () => untracked(() => revision.update((n) => n + 1));
|
|
34
|
+
effect((onCleanup) => {
|
|
35
|
+
if (owner.destroyed) return;
|
|
36
|
+
const current = requested();
|
|
37
|
+
outsideZone(() => untracked(() => {
|
|
38
|
+
try {
|
|
39
|
+
const unsubscribe = current.subscribe?.(invalidate);
|
|
40
|
+
if (unsubscribe) {
|
|
41
|
+
if (owner.destroyed) unsubscribe();
|
|
42
|
+
else onCleanup(() => outsideZone(unsubscribe));
|
|
43
|
+
}
|
|
44
|
+
} finally {
|
|
45
|
+
invalidate();
|
|
46
|
+
}
|
|
47
|
+
}));
|
|
48
|
+
});
|
|
49
|
+
return computed(() => {
|
|
50
|
+
revision();
|
|
51
|
+
return outsideZone(() => requested().getSnapshot());
|
|
52
|
+
}, options?.equal ? { equal: options.equal } : void 0);
|
|
37
53
|
}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
//# sourceMappingURL=inject-external-store.mjs.map
|
|
54
|
+
//#endregion
|
|
55
|
+
export { injectExternalStore };
|
|
56
|
+
|
|
57
|
+
//# sourceMappingURL=inject-external-store.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"inject-external-store.mjs","sources":["../../src/utils/inject-external-store.ts"],"sourcesContent":["import {\n DestroyRef,\n assertInInjectionContext,\n computed,\n effect,\n inject,\n signal,\n untracked,\n} from '@angular/core'\nimport { injectQueryZone } from './inject-query-zone'\nimport type { Signal, ValueEqualityFn } from '@angular/core'\n\ninterface ExternalBinding<T> {\n /** Synchronous snapshot. Angular signals read here are tracked dependencies. */\n readonly getSnapshot: () => T\n /** Omit to pause observation; changing eligibility requires a new descriptor. */\n readonly subscribe?: ((notify: () => void) => () => void) | undefined\n}\n\ninterface ExternalStoreOptions<T> {\n /** Snapshot equality, defaulting to Object.is. Does not control connection identity. */\n readonly equal?: ValueEqualityFn<T> | undefined\n}\n\n/**\n * Creates a readonly Angular signal backed by a synchronous external store.\n *\n * Store access, subscription setup, and cleanup run outside NgZone so background\n * timers do not hold Angular stability open.\n *\n * Reads evaluate snapshots without subscribing. An effect owns the subscription\n * and invalidates the snapshot after setup, closing the gap between an early\n * read and connection. The next read recomputes the snapshot; equality prevents\n * unchanged values from propagating. Unread snapshots stay lazy.\n *\n * Notifications invalidate snapshots synchronously once connected. Snapshot-only\n * dependencies do not reinstall the subscription. Subscription setup and cleanup\n * may read the returned signal; factories and snapshot readers must not recurse.\n *\n * Only factory/snapshot errors are exposed on reads. Subscription and cleanup\n * errors follow Angular's normal effect error handling; the helper does not store\n * them or implement retries. Destruction stops observation without changing the\n * cached snapshot.\n */\nexport function injectExternalStore<T>(\n binding: () => ExternalBinding<T>,\n options?: ExternalStoreOptions<T>,\n): Signal<T> {\n if (typeof ngDevMode === 'undefined' || ngDevMode) {\n assertInInjectionContext(injectExternalStore)\n }\n const owner = inject(DestroyRef)\n const outsideZone = injectQueryZone()\n const revision = signal(0)\n const requested = computed(() => outsideZone(binding))\n const invalidate = () => untracked(() => revision.update((n) => n + 1))\n\n effect((onCleanup) => {\n // The previous subscription's cleanup may have destroyed the owner.\n if (owner.destroyed) return\n const current = requested()\n outsideZone(() =>\n untracked(() => {\n try {\n const unsubscribe = current.subscribe?.(invalidate)\n if (unsubscribe) {\n // subscribe() can trigger component/injector destruction before returning.\n // Registering cleanup afterward misses that destruction.\n if (owner.destroyed) unsubscribe()\n else onCleanup(() => outsideZone(unsubscribe))\n }\n } finally {\n // Invalidate after subscribing so an early cached snapshot cannot miss\n // changes before or during setup. Do not eagerly read the snapshot.\n invalidate()\n }\n }),\n )\n })\n\n return computed(\n () => {\n revision()\n return outsideZone(() => requested().getSnapshot())\n },\n options?.equal ? { equal: options.equal } : undefined,\n )\n}\n"],"
|
|
1
|
+
{"version":3,"file":"inject-external-store.mjs","names":[],"sources":["../../src/utils/inject-external-store.ts"],"sourcesContent":["import {\n DestroyRef,\n assertInInjectionContext,\n computed,\n effect,\n inject,\n signal,\n untracked,\n} from '@angular/core'\nimport { injectQueryZone } from './inject-query-zone'\nimport type { Signal, ValueEqualityFn } from '@angular/core'\n\ninterface ExternalBinding<T> {\n /** Synchronous snapshot. Angular signals read here are tracked dependencies. */\n readonly getSnapshot: () => T\n /** Omit to pause observation; changing eligibility requires a new descriptor. */\n readonly subscribe?: ((notify: () => void) => () => void) | undefined\n}\n\ninterface ExternalStoreOptions<T> {\n /** Snapshot equality, defaulting to Object.is. Does not control connection identity. */\n readonly equal?: ValueEqualityFn<T> | undefined\n}\n\n/**\n * Creates a readonly Angular signal backed by a synchronous external store.\n *\n * Store access, subscription setup, and cleanup run outside NgZone so background\n * timers do not hold Angular stability open.\n *\n * Reads evaluate snapshots without subscribing. An effect owns the subscription\n * and invalidates the snapshot after setup, closing the gap between an early\n * read and connection. The next read recomputes the snapshot; equality prevents\n * unchanged values from propagating. Unread snapshots stay lazy.\n *\n * Notifications invalidate snapshots synchronously once connected. Snapshot-only\n * dependencies do not reinstall the subscription. Subscription setup and cleanup\n * may read the returned signal; factories and snapshot readers must not recurse.\n *\n * Only factory/snapshot errors are exposed on reads. Subscription and cleanup\n * errors follow Angular's normal effect error handling; the helper does not store\n * them or implement retries. Destruction stops observation without changing the\n * cached snapshot.\n * @param binding - Produces the current snapshot reader and optional subscription.\n * @param options - Optional equality comparison for snapshots.\n * @returns A readonly signal containing the latest external snapshot.\n */\nexport function injectExternalStore<T>(\n binding: () => ExternalBinding<T>,\n options?: ExternalStoreOptions<T>,\n): Signal<T> {\n if (typeof ngDevMode === 'undefined' || ngDevMode) {\n assertInInjectionContext(injectExternalStore)\n }\n const owner = inject(DestroyRef)\n const outsideZone = injectQueryZone()\n const revision = signal(0)\n const requested = computed(() => outsideZone(binding))\n const invalidate = () => untracked(() => revision.update((n) => n + 1))\n\n effect((onCleanup) => {\n // The previous subscription's cleanup may have destroyed the owner.\n if (owner.destroyed) return\n const current = requested()\n outsideZone(() =>\n untracked(() => {\n try {\n const unsubscribe = current.subscribe?.(invalidate)\n if (unsubscribe) {\n // subscribe() can trigger component/injector destruction before returning.\n // Registering cleanup afterward misses that destruction.\n if (owner.destroyed) unsubscribe()\n else onCleanup(() => outsideZone(unsubscribe))\n }\n } finally {\n // Invalidate after subscribing so an early cached snapshot cannot miss\n // changes before or during setup. Do not eagerly read the snapshot.\n invalidate()\n }\n }),\n )\n })\n\n return computed(\n () => {\n revision()\n return outsideZone(() => requested().getSnapshot())\n },\n options?.equal ? { equal: options.equal } : undefined,\n )\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AA+CA,SAAgB,oBACd,SACA,SACW;CACX,IAAI,OAAO,cAAc,eAAe,WACtC,yBAAyB,mBAAmB;CAE9C,MAAM,QAAQ,OAAO,UAAU;CAC/B,MAAM,cAAc,gBAAgB;CACpC,MAAM,WAAW,OAAO,CAAC;CACzB,MAAM,YAAY,eAAe,YAAY,OAAO,CAAC;CACrD,MAAM,mBAAmB,gBAAgB,SAAS,QAAQ,MAAM,IAAI,CAAC,CAAC;CAEtE,QAAQ,cAAc;EAEpB,IAAI,MAAM,WAAW;EACrB,MAAM,UAAU,UAAU;EAC1B,kBACE,gBAAgB;GACd,IAAI;IACF,MAAM,cAAc,QAAQ,YAAY,UAAU;IAClD,IAAI,aAAa;KAGf,IAAI,MAAM,WAAW,YAAY;UAC5B,gBAAgB,YAAY,WAAW,CAAC;IAC/C;GACF,UAAU;IAGR,WAAW;GACb;EACF,CAAC,CACH;CACF,CAAC;CAED,OAAO,eACC;EACJ,SAAS;EACT,OAAO,kBAAkB,UAAU,CAAC,CAAC,YAAY,CAAC;CACpD,GACA,SAAS,QAAQ,EAAE,OAAO,QAAQ,MAAM,IAAI,KAAA,CAC9C;AACF"}
|
|
@@ -1,6 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tracks ownership and pending work for the current Angular injection context.
|
|
3
|
+
*/
|
|
1
4
|
export interface QueryLifecycle {
|
|
5
|
+
/**
|
|
6
|
+
* Whether Angular has destroyed the injection context that owns this query.
|
|
7
|
+
*/
|
|
2
8
|
readonly destroyed: boolean;
|
|
9
|
+
/**
|
|
10
|
+
* Adds or releases the task that keeps Angular unstable while owned work is pending.
|
|
11
|
+
*/
|
|
3
12
|
setPending: (pending: boolean) => void;
|
|
4
13
|
}
|
|
5
|
-
/**
|
|
14
|
+
/**
|
|
15
|
+
* Tracks pending work for the lifetime of the current injection context.
|
|
16
|
+
* @returns The destruction state and pending-task controller for this context.
|
|
17
|
+
*/
|
|
6
18
|
export declare function injectPendingTasksLifecycle(): QueryLifecycle;
|
|
@@ -1,31 +1,34 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { DestroyRef, NgZone, PendingTasks, inject } from "@angular/core";
|
|
2
|
+
//#region src/utils/inject-pending-tasks-lifecycle.ts
|
|
3
|
+
/**
|
|
4
|
+
* Tracks pending work for the lifetime of the current injection context.
|
|
5
|
+
* @returns The destruction state and pending-task controller for this context.
|
|
6
|
+
*/
|
|
2
7
|
function injectPendingTasksLifecycle() {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
});
|
|
26
|
-
return lifecycle;
|
|
8
|
+
const destroyRef = inject(DestroyRef);
|
|
9
|
+
const pendingTasks = inject(PendingTasks);
|
|
10
|
+
const ngZone = inject(NgZone);
|
|
11
|
+
let taskCleanup;
|
|
12
|
+
const lifecycle = {
|
|
13
|
+
get destroyed() {
|
|
14
|
+
return destroyRef.destroyed;
|
|
15
|
+
},
|
|
16
|
+
setPending(pending) {
|
|
17
|
+
if (pending) {
|
|
18
|
+
if (!destroyRef.destroyed && !taskCleanup) taskCleanup = pendingTasks.add();
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
const cleanup = taskCleanup;
|
|
22
|
+
taskCleanup = void 0;
|
|
23
|
+
if (cleanup) ngZone.run(cleanup);
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
destroyRef.onDestroy(() => {
|
|
27
|
+
lifecycle.setPending(false);
|
|
28
|
+
});
|
|
29
|
+
return lifecycle;
|
|
27
30
|
}
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
//# sourceMappingURL=inject-pending-tasks-lifecycle.mjs.map
|
|
31
|
+
//#endregion
|
|
32
|
+
export { injectPendingTasksLifecycle };
|
|
33
|
+
|
|
34
|
+
//# sourceMappingURL=inject-pending-tasks-lifecycle.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"inject-pending-tasks-lifecycle.mjs","sources":["../../src/utils/inject-pending-tasks-lifecycle.ts"],"sourcesContent":["import { DestroyRef, NgZone, PendingTasks, inject } from '@angular/core'\n\nexport interface QueryLifecycle {\n readonly destroyed: boolean\n setPending: (pending: boolean) => void\n}\n\n
|
|
1
|
+
{"version":3,"file":"inject-pending-tasks-lifecycle.mjs","names":[],"sources":["../../src/utils/inject-pending-tasks-lifecycle.ts"],"sourcesContent":["import { DestroyRef, NgZone, PendingTasks, inject } from '@angular/core'\n\n/**\n * Tracks ownership and pending work for the current Angular injection context.\n */\nexport interface QueryLifecycle {\n /**\n * Whether Angular has destroyed the injection context that owns this query.\n */\n readonly destroyed: boolean\n /**\n * Adds or releases the task that keeps Angular unstable while owned work is pending.\n */\n setPending: (pending: boolean) => void\n}\n\n/**\n * Tracks pending work for the lifetime of the current injection context.\n * @returns The destruction state and pending-task controller for this context.\n */\nexport function injectPendingTasksLifecycle(): QueryLifecycle {\n const destroyRef = inject(DestroyRef)\n const pendingTasks = inject(PendingTasks)\n const ngZone = inject(NgZone)\n let taskCleanup: (() => void) | undefined\n\n const lifecycle: QueryLifecycle = {\n get destroyed() {\n return destroyRef.destroyed\n },\n setPending(pending) {\n if (pending) {\n if (!destroyRef.destroyed && !taskCleanup) {\n taskCleanup = pendingTasks.add()\n }\n return\n }\n\n const cleanup = taskCleanup\n taskCleanup = undefined\n // Enter NgZone while our task is still held to avoid transient stability\n // before dependent queries are scheduled.\n // In zoneless apps, NgZone.run simply invokes the cleanup.\n if (cleanup) ngZone.run(cleanup)\n },\n }\n\n destroyRef.onDestroy(() => {\n lifecycle.setPending(false)\n })\n\n return lifecycle\n}\n"],"mappings":";;;;;;AAoBA,SAAgB,8BAA8C;CAC5D,MAAM,aAAa,OAAO,UAAU;CACpC,MAAM,eAAe,OAAO,YAAY;CACxC,MAAM,SAAS,OAAO,MAAM;CAC5B,IAAI;CAEJ,MAAM,YAA4B;EAChC,IAAI,YAAY;GACd,OAAO,WAAW;EACpB;EACA,WAAW,SAAS;GAClB,IAAI,SAAS;IACX,IAAI,CAAC,WAAW,aAAa,CAAC,aAC5B,cAAc,aAAa,IAAI;IAEjC;GACF;GAEA,MAAM,UAAU;GAChB,cAAc,KAAA;GAId,IAAI,SAAS,OAAO,IAAI,OAAO;EACjC;CACF;CAEA,WAAW,gBAAgB;EACzB,UAAU,WAAW,KAAK;CAC5B,CAAC;CAED,OAAO;AACT"}
|
|
@@ -1,2 +1,5 @@
|
|
|
1
|
-
/**
|
|
1
|
+
/**
|
|
2
|
+
* Keeps Query's background timers out of Angular's stability tracking.
|
|
3
|
+
* @returns A function that runs callbacks outside the injected NgZone.
|
|
4
|
+
*/
|
|
2
5
|
export declare function injectQueryZone(): <T>(fn: () => T) => T;
|