@tanstack/angular-query-experimental 5.34.2 → 5.35.1
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/build/rollup.d.ts +591 -0
- package/package.json +10 -6
- package/build/create-base-query.d.ts +0 -6
- package/build/index.d.ts +0 -14
- package/build/infinite-query-options.d.ts +0 -34
- package/build/inject-infinite-query.d.ts +0 -31
- package/build/inject-is-fetching.d.ts +0 -13
- package/build/inject-is-mutating.d.ts +0 -12
- package/build/inject-mutation-state.d.ts +0 -21
- package/build/inject-mutation.d.ts +0 -13
- package/build/inject-queries.d.ts +0 -76
- package/build/inject-query-client.d.ts +0 -30
- package/build/inject-query.d.ts +0 -106
- package/build/providers.d.ts +0 -42
- package/build/query-options.d.ts +0 -66
- package/build/signal-proxy.d.ts +0 -11
- package/build/types.d.ts +0 -95
- package/build/util/assert-injector/assert-injector.d.ts +0 -54
- package/build/util/create-injection-token/create-injection-token.d.ts +0 -52
- package/build/util/index.d.ts +0 -2
- package/build/util/lazy-init/lazy-init.d.ts +0 -1
- package/build/util/lazy-signal-initializer/lazy-signal-initializer.d.ts +0 -4
- package/src/__tests__/inject-infinite-query.test.ts +0 -64
- package/src/__tests__/inject-is-fetching.test.ts +0 -35
- package/src/__tests__/inject-is-mutating.test.ts +0 -39
- package/src/__tests__/inject-mutation-state.test-d.ts +0 -22
- package/src/__tests__/inject-mutation-state.test.ts +0 -175
- package/src/__tests__/inject-mutation.test-d.ts +0 -71
- package/src/__tests__/inject-mutation.test.ts +0 -458
- package/src/__tests__/inject-query.test-d.ts +0 -59
- package/src/__tests__/inject-query.test.ts +0 -349
- package/src/__tests__/query-options.test-d.ts +0 -127
- package/src/__tests__/signal-proxy.test.ts +0 -27
- package/src/__tests__/test-utils.ts +0 -131
- package/src/__tests__/util/lazy-init/lazy-init.test.ts +0 -126
- package/src/__tests__/util/lazy-signal-initializer/lazy-signal-initializer.test.ts +0 -130
- package/src/create-base-query.ts +0 -116
- package/src/index.ts +0 -24
- package/src/infinite-query-options.ts +0 -118
- package/src/inject-infinite-query.ts +0 -125
- package/src/inject-is-fetching.ts +0 -49
- package/src/inject-is-mutating.ts +0 -48
- package/src/inject-mutation-state.ts +0 -107
- package/src/inject-mutation.ts +0 -118
- package/src/inject-queries.ts +0 -265
- package/src/inject-query-client.ts +0 -25
- package/src/inject-query.ts +0 -200
- package/src/providers.ts +0 -65
- package/src/query-options.ts +0 -122
- package/src/signal-proxy.ts +0 -46
- package/src/test-setup.ts +0 -12
- package/src/types.ts +0 -311
- package/src/util/assert-injector/assert-injector.test.ts +0 -74
- package/src/util/assert-injector/assert-injector.ts +0 -81
- package/src/util/create-injection-token/create-injection-token.test.ts +0 -32
- package/src/util/create-injection-token/create-injection-token.ts +0 -185
- package/src/util/index.ts +0 -13
- package/src/util/lazy-init/lazy-init.ts +0 -34
- package/src/util/lazy-signal-initializer/lazy-signal-initializer.ts +0 -28
package/src/inject-query.ts
DELETED
|
@@ -1,200 +0,0 @@
|
|
|
1
|
-
import { QueryObserver } from '@tanstack/query-core'
|
|
2
|
-
import { runInInjectionContext } from '@angular/core'
|
|
3
|
-
import { assertInjector } from './util/assert-injector/assert-injector'
|
|
4
|
-
import { injectQueryClient } from './inject-query-client'
|
|
5
|
-
import { createBaseQuery } from './create-base-query'
|
|
6
|
-
import type { DefaultError, QueryClient, QueryKey } from '@tanstack/query-core'
|
|
7
|
-
import type { Injector } from '@angular/core'
|
|
8
|
-
import type {
|
|
9
|
-
CreateQueryOptions,
|
|
10
|
-
CreateQueryResult,
|
|
11
|
-
DefinedCreateQueryResult,
|
|
12
|
-
} from './types'
|
|
13
|
-
import type {
|
|
14
|
-
DefinedInitialDataOptions,
|
|
15
|
-
UndefinedInitialDataOptions,
|
|
16
|
-
} from './query-options'
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Injects a query: a declarative dependency on an asynchronous source of data that is tied to a unique key.
|
|
20
|
-
*
|
|
21
|
-
* **Basic example**
|
|
22
|
-
* ```ts
|
|
23
|
-
* class ServiceOrComponent {
|
|
24
|
-
* query = injectQuery(() => ({
|
|
25
|
-
* queryKey: ['repoData'],
|
|
26
|
-
* queryFn: () =>
|
|
27
|
-
* this.#http.get<Response>('https://api.github.com/repos/tanstack/query'),
|
|
28
|
-
* }))
|
|
29
|
-
* }
|
|
30
|
-
* ```
|
|
31
|
-
*
|
|
32
|
-
* **The options function can utilize signals**
|
|
33
|
-
* ```ts
|
|
34
|
-
* class ServiceOrComponent {
|
|
35
|
-
* filter = signal('')
|
|
36
|
-
*
|
|
37
|
-
* todosQuery = injectQuery(() => ({
|
|
38
|
-
* queryKey: ['todos', this.filter()],
|
|
39
|
-
* queryFn: () => fetchTodos(this.filter()),
|
|
40
|
-
* // Signals can be combined with expressions
|
|
41
|
-
* enabled: !!this.filter(),
|
|
42
|
-
* }))
|
|
43
|
-
* }
|
|
44
|
-
* ```
|
|
45
|
-
* @param optionsFn - A function that returns query options.
|
|
46
|
-
* @param injector - The Angular injector to use.
|
|
47
|
-
* @returns The query result.
|
|
48
|
-
* @public
|
|
49
|
-
* @see https://tanstack.com/query/latest/docs/framework/angular/guides/queries
|
|
50
|
-
*/
|
|
51
|
-
export function injectQuery<
|
|
52
|
-
TQueryFnData = unknown,
|
|
53
|
-
TError = DefaultError,
|
|
54
|
-
TData = TQueryFnData,
|
|
55
|
-
TQueryKey extends QueryKey = QueryKey,
|
|
56
|
-
>(
|
|
57
|
-
optionsFn: (
|
|
58
|
-
client: QueryClient,
|
|
59
|
-
) => DefinedInitialDataOptions<TQueryFnData, TError, TData, TQueryKey>,
|
|
60
|
-
injector?: Injector,
|
|
61
|
-
): DefinedCreateQueryResult<TData, TError>
|
|
62
|
-
|
|
63
|
-
/**
|
|
64
|
-
* Injects a query: a declarative dependency on an asynchronous source of data that is tied to a unique key.
|
|
65
|
-
*
|
|
66
|
-
* **Basic example**
|
|
67
|
-
* ```ts
|
|
68
|
-
* class ServiceOrComponent {
|
|
69
|
-
* query = injectQuery(() => ({
|
|
70
|
-
* queryKey: ['repoData'],
|
|
71
|
-
* queryFn: () =>
|
|
72
|
-
* this.#http.get<Response>('https://api.github.com/repos/tanstack/query'),
|
|
73
|
-
* }))
|
|
74
|
-
* }
|
|
75
|
-
* ```
|
|
76
|
-
*
|
|
77
|
-
* **The options function can utilize signals**
|
|
78
|
-
* ```ts
|
|
79
|
-
* class ServiceOrComponent {
|
|
80
|
-
* filter = signal('')
|
|
81
|
-
*
|
|
82
|
-
* todosQuery = injectQuery(() => ({
|
|
83
|
-
* queryKey: ['todos', this.filter()],
|
|
84
|
-
* queryFn: () => fetchTodos(this.filter()),
|
|
85
|
-
* // Signals can be combined with expressions
|
|
86
|
-
* enabled: !!this.filter(),
|
|
87
|
-
* }))
|
|
88
|
-
* }
|
|
89
|
-
* ```
|
|
90
|
-
* @param optionsFn - A function that returns query options.
|
|
91
|
-
* @param injector - The Angular injector to use.
|
|
92
|
-
* @returns The query result.
|
|
93
|
-
* @public
|
|
94
|
-
* @see https://tanstack.com/query/latest/docs/framework/angular/guides/queries
|
|
95
|
-
*/
|
|
96
|
-
export function injectQuery<
|
|
97
|
-
TQueryFnData = unknown,
|
|
98
|
-
TError = DefaultError,
|
|
99
|
-
TData = TQueryFnData,
|
|
100
|
-
TQueryKey extends QueryKey = QueryKey,
|
|
101
|
-
>(
|
|
102
|
-
optionsFn: (
|
|
103
|
-
client: QueryClient,
|
|
104
|
-
) => UndefinedInitialDataOptions<TQueryFnData, TError, TData, TQueryKey>,
|
|
105
|
-
injector?: Injector,
|
|
106
|
-
): CreateQueryResult<TData, TError>
|
|
107
|
-
|
|
108
|
-
/**
|
|
109
|
-
* Injects a query: a declarative dependency on an asynchronous source of data that is tied to a unique key.
|
|
110
|
-
*
|
|
111
|
-
* **Basic example**
|
|
112
|
-
* ```ts
|
|
113
|
-
* class ServiceOrComponent {
|
|
114
|
-
* query = injectQuery(() => ({
|
|
115
|
-
* queryKey: ['repoData'],
|
|
116
|
-
* queryFn: () =>
|
|
117
|
-
* this.#http.get<Response>('https://api.github.com/repos/tanstack/query'),
|
|
118
|
-
* }))
|
|
119
|
-
* }
|
|
120
|
-
* ```
|
|
121
|
-
*
|
|
122
|
-
* **The options function can utilize signals**
|
|
123
|
-
* ```ts
|
|
124
|
-
* class ServiceOrComponent {
|
|
125
|
-
* filter = signal('')
|
|
126
|
-
*
|
|
127
|
-
* todosQuery = injectQuery(() => ({
|
|
128
|
-
* queryKey: ['todos', this.filter()],
|
|
129
|
-
* queryFn: () => fetchTodos(this.filter()),
|
|
130
|
-
* // Signals can be combined with expressions
|
|
131
|
-
* enabled: !!this.filter(),
|
|
132
|
-
* }))
|
|
133
|
-
* }
|
|
134
|
-
* ```
|
|
135
|
-
* @param optionsFn - A function that returns query options.
|
|
136
|
-
* @param injector - The Angular injector to use.
|
|
137
|
-
* @returns The query result.
|
|
138
|
-
* @public
|
|
139
|
-
* @see https://tanstack.com/query/latest/docs/framework/angular/guides/queries
|
|
140
|
-
*/
|
|
141
|
-
export function injectQuery<
|
|
142
|
-
TQueryFnData = unknown,
|
|
143
|
-
TError = DefaultError,
|
|
144
|
-
TData = TQueryFnData,
|
|
145
|
-
TQueryKey extends QueryKey = QueryKey,
|
|
146
|
-
>(
|
|
147
|
-
optionsFn: (
|
|
148
|
-
client: QueryClient,
|
|
149
|
-
) => CreateQueryOptions<TQueryFnData, TError, TData, TQueryKey>,
|
|
150
|
-
injector?: Injector,
|
|
151
|
-
): CreateQueryResult<TData, TError>
|
|
152
|
-
|
|
153
|
-
/**
|
|
154
|
-
* Injects a query: a declarative dependency on an asynchronous source of data that is tied to a unique key.
|
|
155
|
-
*
|
|
156
|
-
* **Basic example**
|
|
157
|
-
* ```ts
|
|
158
|
-
* class ServiceOrComponent {
|
|
159
|
-
* query = injectQuery(() => ({
|
|
160
|
-
* queryKey: ['repoData'],
|
|
161
|
-
* queryFn: () =>
|
|
162
|
-
* this.#http.get<Response>('https://api.github.com/repos/tanstack/query'),
|
|
163
|
-
* }))
|
|
164
|
-
* }
|
|
165
|
-
* ```
|
|
166
|
-
*
|
|
167
|
-
* **The options function can utilize signals**
|
|
168
|
-
* ```ts
|
|
169
|
-
* class ServiceOrComponent {
|
|
170
|
-
* filter = signal('')
|
|
171
|
-
*
|
|
172
|
-
* todosQuery = injectQuery(() => ({
|
|
173
|
-
* queryKey: ['todos', this.filter()],
|
|
174
|
-
* queryFn: () => fetchTodos(this.filter()),
|
|
175
|
-
* // Signals can be combined with expressions
|
|
176
|
-
* enabled: !!this.filter(),
|
|
177
|
-
* }))
|
|
178
|
-
* }
|
|
179
|
-
* ```
|
|
180
|
-
* @param optionsFn - A function that returns query options.
|
|
181
|
-
* @param injector - The Angular injector to use.
|
|
182
|
-
* @returns The query result.
|
|
183
|
-
* @public
|
|
184
|
-
* @see https://tanstack.com/query/latest/docs/framework/angular/guides/queries
|
|
185
|
-
*/
|
|
186
|
-
export function injectQuery(
|
|
187
|
-
optionsFn: (client: QueryClient) => CreateQueryOptions,
|
|
188
|
-
injector?: Injector,
|
|
189
|
-
) {
|
|
190
|
-
const assertedInjector = assertInjector(injectQuery, injector)
|
|
191
|
-
return assertInjector(injectQuery, injector, () => {
|
|
192
|
-
const queryClient = injectQueryClient()
|
|
193
|
-
return createBaseQuery(
|
|
194
|
-
(client) =>
|
|
195
|
-
runInInjectionContext(assertedInjector, () => optionsFn(client)),
|
|
196
|
-
QueryObserver,
|
|
197
|
-
queryClient,
|
|
198
|
-
)
|
|
199
|
-
})
|
|
200
|
-
}
|
package/src/providers.ts
DELETED
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
DestroyRef,
|
|
3
|
-
ENVIRONMENT_INITIALIZER,
|
|
4
|
-
inject,
|
|
5
|
-
makeEnvironmentProviders,
|
|
6
|
-
} from '@angular/core'
|
|
7
|
-
import { provideQueryClient } from './inject-query-client'
|
|
8
|
-
import type { EnvironmentProviders } from '@angular/core'
|
|
9
|
-
import type { QueryClient } from '@tanstack/query-core'
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Sets up providers necessary to enable TanStack Query functionality for Angular applications.
|
|
13
|
-
*
|
|
14
|
-
* Allows to configure a `QueryClient`.
|
|
15
|
-
*
|
|
16
|
-
* **Example - standalone**
|
|
17
|
-
*
|
|
18
|
-
* ```ts
|
|
19
|
-
* import {
|
|
20
|
-
* provideAngularQuery,
|
|
21
|
-
* QueryClient,
|
|
22
|
-
* } from '@tanstack/angular-query-experimental'
|
|
23
|
-
*
|
|
24
|
-
* bootstrapApplication(AppComponent, {
|
|
25
|
-
* providers: [provideAngularQuery(new QueryClient())],
|
|
26
|
-
* })
|
|
27
|
-
* ```
|
|
28
|
-
*
|
|
29
|
-
* **Example - NgModule-based**
|
|
30
|
-
*
|
|
31
|
-
* ```ts
|
|
32
|
-
* import {
|
|
33
|
-
* provideAngularQuery,
|
|
34
|
-
* QueryClient,
|
|
35
|
-
* } from '@tanstack/angular-query-experimental'
|
|
36
|
-
*
|
|
37
|
-
* @NgModule({
|
|
38
|
-
* declarations: [AppComponent],
|
|
39
|
-
* imports: [BrowserModule],
|
|
40
|
-
* providers: [provideAngularQuery(new QueryClient())],
|
|
41
|
-
* bootstrap: [AppComponent],
|
|
42
|
-
* })
|
|
43
|
-
* export class AppModule {}
|
|
44
|
-
* ```
|
|
45
|
-
* @param queryClient - A `QueryClient` instance.
|
|
46
|
-
* @returns A set of providers to set up TanStack Query.
|
|
47
|
-
* @public
|
|
48
|
-
* @see https://tanstack.com/query/v5/docs/framework/angular/quick-start
|
|
49
|
-
*/
|
|
50
|
-
export function provideAngularQuery(
|
|
51
|
-
queryClient: QueryClient,
|
|
52
|
-
): EnvironmentProviders {
|
|
53
|
-
return makeEnvironmentProviders([
|
|
54
|
-
provideQueryClient(queryClient),
|
|
55
|
-
{
|
|
56
|
-
provide: ENVIRONMENT_INITIALIZER,
|
|
57
|
-
multi: true,
|
|
58
|
-
useValue: () => {
|
|
59
|
-
queryClient.mount()
|
|
60
|
-
// Unmount the query client on application destroy
|
|
61
|
-
inject(DestroyRef).onDestroy(() => queryClient.unmount())
|
|
62
|
-
},
|
|
63
|
-
},
|
|
64
|
-
])
|
|
65
|
-
}
|
package/src/query-options.ts
DELETED
|
@@ -1,122 +0,0 @@
|
|
|
1
|
-
import type { DataTag, DefaultError, QueryKey } from '@tanstack/query-core'
|
|
2
|
-
import type { CreateQueryOptions } from './types'
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* @public
|
|
6
|
-
*/
|
|
7
|
-
export type UndefinedInitialDataOptions<
|
|
8
|
-
TQueryFnData = unknown,
|
|
9
|
-
TError = DefaultError,
|
|
10
|
-
TData = TQueryFnData,
|
|
11
|
-
TQueryKey extends QueryKey = QueryKey,
|
|
12
|
-
> = CreateQueryOptions<TQueryFnData, TError, TData, TQueryKey> & {
|
|
13
|
-
initialData?: undefined
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
type NonUndefinedGuard<T> = T extends undefined ? never : T
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* @public
|
|
20
|
-
*/
|
|
21
|
-
export type DefinedInitialDataOptions<
|
|
22
|
-
TQueryFnData = unknown,
|
|
23
|
-
TError = DefaultError,
|
|
24
|
-
TData = TQueryFnData,
|
|
25
|
-
TQueryKey extends QueryKey = QueryKey,
|
|
26
|
-
> = CreateQueryOptions<TQueryFnData, TError, TData, TQueryKey> & {
|
|
27
|
-
initialData:
|
|
28
|
-
| NonUndefinedGuard<TQueryFnData>
|
|
29
|
-
| (() => NonUndefinedGuard<TQueryFnData>)
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* Allows to share and re-use query options in a type-safe way.
|
|
34
|
-
*
|
|
35
|
-
* The `queryKey` will be tagged with the type from `queryFn`.
|
|
36
|
-
*
|
|
37
|
-
* **Example**
|
|
38
|
-
*
|
|
39
|
-
* ```ts
|
|
40
|
-
* const { queryKey } = queryOptions({
|
|
41
|
-
* queryKey: ['key'],
|
|
42
|
-
* queryFn: () => Promise.resolve(5),
|
|
43
|
-
* // ^? Promise<number>
|
|
44
|
-
* })
|
|
45
|
-
*
|
|
46
|
-
* const queryClient = new QueryClient()
|
|
47
|
-
* const data = queryClient.getQueryData(queryKey)
|
|
48
|
-
* // ^? number | undefined
|
|
49
|
-
* ```
|
|
50
|
-
* @param options - The query options to tag with the type from `queryFn`.
|
|
51
|
-
* @returns The tagged query options.
|
|
52
|
-
* @public
|
|
53
|
-
*/
|
|
54
|
-
export function queryOptions<
|
|
55
|
-
TQueryFnData = unknown,
|
|
56
|
-
TError = DefaultError,
|
|
57
|
-
TData = TQueryFnData,
|
|
58
|
-
TQueryKey extends QueryKey = QueryKey,
|
|
59
|
-
>(
|
|
60
|
-
options: UndefinedInitialDataOptions<TQueryFnData, TError, TData, TQueryKey>,
|
|
61
|
-
): UndefinedInitialDataOptions<TQueryFnData, TError, TData, TQueryKey> & {
|
|
62
|
-
queryKey: DataTag<TQueryKey, TQueryFnData>
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
/**
|
|
66
|
-
* Allows to share and re-use query options in a type-safe way.
|
|
67
|
-
*
|
|
68
|
-
* The `queryKey` will be tagged with the type from `queryFn`.
|
|
69
|
-
*
|
|
70
|
-
* **Example**
|
|
71
|
-
*
|
|
72
|
-
* ```ts
|
|
73
|
-
* const { queryKey } = queryOptions({
|
|
74
|
-
* queryKey: ['key'],
|
|
75
|
-
* queryFn: () => Promise.resolve(5),
|
|
76
|
-
* // ^? Promise<number>
|
|
77
|
-
* })
|
|
78
|
-
*
|
|
79
|
-
* const queryClient = new QueryClient()
|
|
80
|
-
* const data = queryClient.getQueryData(queryKey)
|
|
81
|
-
* // ^? number | undefined
|
|
82
|
-
* ```
|
|
83
|
-
* @param options - The query options to tag with the type from `queryFn`.
|
|
84
|
-
* @returns The tagged query options.
|
|
85
|
-
* @public
|
|
86
|
-
*/
|
|
87
|
-
export function queryOptions<
|
|
88
|
-
TQueryFnData = unknown,
|
|
89
|
-
TError = DefaultError,
|
|
90
|
-
TData = TQueryFnData,
|
|
91
|
-
TQueryKey extends QueryKey = QueryKey,
|
|
92
|
-
>(
|
|
93
|
-
options: DefinedInitialDataOptions<TQueryFnData, TError, TData, TQueryKey>,
|
|
94
|
-
): DefinedInitialDataOptions<TQueryFnData, TError, TData, TQueryKey> & {
|
|
95
|
-
queryKey: DataTag<TQueryKey, TQueryFnData>
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
/**
|
|
99
|
-
* Allows to share and re-use query options in a type-safe way.
|
|
100
|
-
*
|
|
101
|
-
* The `queryKey` will be tagged with the type from `queryFn`.
|
|
102
|
-
*
|
|
103
|
-
* **Example**
|
|
104
|
-
*
|
|
105
|
-
* ```ts
|
|
106
|
-
* const { queryKey } = queryOptions({
|
|
107
|
-
* queryKey: ['key'],
|
|
108
|
-
* queryFn: () => Promise.resolve(5),
|
|
109
|
-
* // ^? Promise<number>
|
|
110
|
-
* })
|
|
111
|
-
*
|
|
112
|
-
* const queryClient = new QueryClient()
|
|
113
|
-
* const data = queryClient.getQueryData(queryKey)
|
|
114
|
-
* // ^? number | undefined
|
|
115
|
-
* ```
|
|
116
|
-
* @param options - The query options to tag with the type from `queryFn`.
|
|
117
|
-
* @returns The tagged query options.
|
|
118
|
-
* @public
|
|
119
|
-
*/
|
|
120
|
-
export function queryOptions(options: unknown) {
|
|
121
|
-
return options
|
|
122
|
-
}
|
package/src/signal-proxy.ts
DELETED
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import { computed, untracked } from '@angular/core'
|
|
2
|
-
import type { Signal } from '@angular/core'
|
|
3
|
-
|
|
4
|
-
export type MapToSignals<T> = {
|
|
5
|
-
[K in keyof T]: T[K] extends Function ? T[K] : Signal<T[K]>
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Exposes fields of an object passed via an Angular `Signal` as `Computed` signals.
|
|
10
|
-
* Functions on the object are passed through as-is.
|
|
11
|
-
* @param inputSignal - `Signal` that must return an object.
|
|
12
|
-
* @returns A proxy object with the same fields as the input object, but with each field wrapped in a `Computed` signal.
|
|
13
|
-
*/
|
|
14
|
-
export function signalProxy<TInput extends Record<string | symbol, any>>(
|
|
15
|
-
inputSignal: Signal<TInput>,
|
|
16
|
-
) {
|
|
17
|
-
const internalState = {} as MapToSignals<TInput>
|
|
18
|
-
|
|
19
|
-
return new Proxy<MapToSignals<TInput>>(internalState, {
|
|
20
|
-
get(target, prop) {
|
|
21
|
-
// first check if we have it in our internal state and return it
|
|
22
|
-
const computedField = target[prop]
|
|
23
|
-
if (computedField) return computedField
|
|
24
|
-
|
|
25
|
-
// then, check if it's a function on the resultState and return it
|
|
26
|
-
const targetField = untracked(inputSignal)[prop]
|
|
27
|
-
if (typeof targetField === 'function') return targetField
|
|
28
|
-
|
|
29
|
-
// finally, create a computed field, store it and return it
|
|
30
|
-
// @ts-expect-error
|
|
31
|
-
return (target[prop] = computed(() => inputSignal()[prop]))
|
|
32
|
-
},
|
|
33
|
-
has(_, prop) {
|
|
34
|
-
return !!untracked(inputSignal)[prop]
|
|
35
|
-
},
|
|
36
|
-
ownKeys() {
|
|
37
|
-
return Reflect.ownKeys(untracked(inputSignal))
|
|
38
|
-
},
|
|
39
|
-
getOwnPropertyDescriptor() {
|
|
40
|
-
return {
|
|
41
|
-
enumerable: true,
|
|
42
|
-
configurable: true,
|
|
43
|
-
}
|
|
44
|
-
},
|
|
45
|
-
})
|
|
46
|
-
}
|
package/src/test-setup.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import '@analogjs/vite-plugin-angular/setup-vitest'
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
BrowserDynamicTestingModule,
|
|
5
|
-
platformBrowserDynamicTesting,
|
|
6
|
-
} from '@angular/platform-browser-dynamic/testing'
|
|
7
|
-
import { getTestBed } from '@angular/core/testing'
|
|
8
|
-
|
|
9
|
-
getTestBed().initTestEnvironment(
|
|
10
|
-
BrowserDynamicTestingModule,
|
|
11
|
-
platformBrowserDynamicTesting(),
|
|
12
|
-
)
|