@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
|
@@ -1,126 +0,0 @@
|
|
|
1
|
-
import { describe, expect, test } from 'vitest'
|
|
2
|
-
import {
|
|
3
|
-
ChangeDetectionStrategy,
|
|
4
|
-
Component,
|
|
5
|
-
type WritableSignal,
|
|
6
|
-
computed,
|
|
7
|
-
effect,
|
|
8
|
-
input,
|
|
9
|
-
signal,
|
|
10
|
-
} from '@angular/core'
|
|
11
|
-
import { TestBed } from '@angular/core/testing'
|
|
12
|
-
import { flushQueue, setFixtureSignalInputs } from '../../test-utils'
|
|
13
|
-
import { lazyInit } from '../../../util/lazy-init/lazy-init'
|
|
14
|
-
|
|
15
|
-
describe('lazyInit', () => {
|
|
16
|
-
test('should init lazily in next tick when not accessing manually', async () => {
|
|
17
|
-
const mockFn = vi.fn()
|
|
18
|
-
|
|
19
|
-
TestBed.runInInjectionContext(() => {
|
|
20
|
-
lazyInit(() => {
|
|
21
|
-
mockFn()
|
|
22
|
-
return {
|
|
23
|
-
data: signal(true),
|
|
24
|
-
}
|
|
25
|
-
})
|
|
26
|
-
})
|
|
27
|
-
|
|
28
|
-
expect(mockFn).not.toHaveBeenCalled()
|
|
29
|
-
|
|
30
|
-
await new Promise(setImmediate)
|
|
31
|
-
|
|
32
|
-
expect(mockFn).toHaveBeenCalled()
|
|
33
|
-
})
|
|
34
|
-
|
|
35
|
-
test('should init eagerly accessing manually', async () => {
|
|
36
|
-
const mockFn = vi.fn()
|
|
37
|
-
|
|
38
|
-
TestBed.runInInjectionContext(() => {
|
|
39
|
-
const lazySignal = lazyInit(() => {
|
|
40
|
-
mockFn()
|
|
41
|
-
return {
|
|
42
|
-
data: signal(true),
|
|
43
|
-
}
|
|
44
|
-
})
|
|
45
|
-
|
|
46
|
-
lazySignal.data()
|
|
47
|
-
|
|
48
|
-
console.log(lazySignal)
|
|
49
|
-
})
|
|
50
|
-
|
|
51
|
-
expect(mockFn).toHaveBeenCalled()
|
|
52
|
-
})
|
|
53
|
-
|
|
54
|
-
test('should init lazily and only once', async () => {
|
|
55
|
-
const initCallFn = vi.fn()
|
|
56
|
-
const registerDataValue = vi.fn<[number]>()
|
|
57
|
-
|
|
58
|
-
let value!: { data: WritableSignal<number> }
|
|
59
|
-
const outerSignal = signal(0)
|
|
60
|
-
|
|
61
|
-
TestBed.runInInjectionContext(() => {
|
|
62
|
-
value = lazyInit(() => {
|
|
63
|
-
initCallFn()
|
|
64
|
-
|
|
65
|
-
void outerSignal()
|
|
66
|
-
|
|
67
|
-
return { data: signal(0) }
|
|
68
|
-
})
|
|
69
|
-
|
|
70
|
-
effect(() => registerDataValue(value.data()))
|
|
71
|
-
})
|
|
72
|
-
|
|
73
|
-
value.data()
|
|
74
|
-
|
|
75
|
-
await flushQueue()
|
|
76
|
-
|
|
77
|
-
expect(outerSignal).toBeDefined()
|
|
78
|
-
|
|
79
|
-
expect(initCallFn).toHaveBeenCalledTimes(1)
|
|
80
|
-
|
|
81
|
-
outerSignal.set(1)
|
|
82
|
-
await flushQueue()
|
|
83
|
-
outerSignal.set(2)
|
|
84
|
-
await flushQueue()
|
|
85
|
-
value.data.set(4)
|
|
86
|
-
await flushQueue()
|
|
87
|
-
|
|
88
|
-
expect(initCallFn).toHaveBeenCalledTimes(1)
|
|
89
|
-
expect(registerDataValue).toHaveBeenCalledTimes(2)
|
|
90
|
-
})
|
|
91
|
-
|
|
92
|
-
test('should support required signal input', async () => {
|
|
93
|
-
@Component({
|
|
94
|
-
standalone: true,
|
|
95
|
-
template: `{{ call }} - {{ lazySignal.data() }}`,
|
|
96
|
-
changeDetection: ChangeDetectionStrategy.OnPush,
|
|
97
|
-
})
|
|
98
|
-
class Test {
|
|
99
|
-
readonly title = input.required<string>()
|
|
100
|
-
call = 0
|
|
101
|
-
|
|
102
|
-
lazySignal = lazyInit(() => {
|
|
103
|
-
this.call++
|
|
104
|
-
return {
|
|
105
|
-
data: computed(() => this.title()),
|
|
106
|
-
}
|
|
107
|
-
})
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
const fixture = TestBed.createComponent(Test)
|
|
111
|
-
|
|
112
|
-
setFixtureSignalInputs(fixture, { title: 'newValue' })
|
|
113
|
-
expect(fixture.debugElement.nativeElement.textContent).toBe('0 - newValue')
|
|
114
|
-
await flushQueue()
|
|
115
|
-
|
|
116
|
-
setFixtureSignalInputs(fixture, { title: 'updatedValue' })
|
|
117
|
-
expect(fixture.debugElement.nativeElement.textContent).toBe(
|
|
118
|
-
'1 - updatedValue',
|
|
119
|
-
)
|
|
120
|
-
|
|
121
|
-
setFixtureSignalInputs(fixture, { title: 'newUpdatedValue' })
|
|
122
|
-
expect(fixture.debugElement.nativeElement.textContent).toBe(
|
|
123
|
-
'1 - newUpdatedValue',
|
|
124
|
-
)
|
|
125
|
-
})
|
|
126
|
-
})
|
|
@@ -1,130 +0,0 @@
|
|
|
1
|
-
import { describe, expect, test } from 'vitest'
|
|
2
|
-
import {
|
|
3
|
-
Component,
|
|
4
|
-
type Signal,
|
|
5
|
-
type WritableSignal,
|
|
6
|
-
effect,
|
|
7
|
-
input,
|
|
8
|
-
signal,
|
|
9
|
-
} from '@angular/core'
|
|
10
|
-
import { TestBed } from '@angular/core/testing'
|
|
11
|
-
import { lazySignalInitializer } from '../../../util/lazy-signal-initializer/lazy-signal-initializer'
|
|
12
|
-
import { flushQueue, setFixtureSignalInputs } from '../../test-utils'
|
|
13
|
-
|
|
14
|
-
describe('lazySignalInitializer', () => {
|
|
15
|
-
test('should init lazily in next tick when not accessing manually', async () => {
|
|
16
|
-
const mockFn = vi.fn()
|
|
17
|
-
|
|
18
|
-
TestBed.runInInjectionContext(() => {
|
|
19
|
-
lazySignalInitializer(() => {
|
|
20
|
-
mockFn()
|
|
21
|
-
return signal(true)
|
|
22
|
-
})
|
|
23
|
-
})
|
|
24
|
-
|
|
25
|
-
expect(mockFn).not.toHaveBeenCalled()
|
|
26
|
-
|
|
27
|
-
await new Promise(setImmediate)
|
|
28
|
-
|
|
29
|
-
expect(mockFn).toHaveBeenCalled()
|
|
30
|
-
})
|
|
31
|
-
|
|
32
|
-
test('should init eagerly accessing manually', async () => {
|
|
33
|
-
const mockFn = vi.fn()
|
|
34
|
-
|
|
35
|
-
TestBed.runInInjectionContext(() => {
|
|
36
|
-
const lazySignal = lazySignalInitializer(() => {
|
|
37
|
-
mockFn()
|
|
38
|
-
return signal(true)
|
|
39
|
-
})
|
|
40
|
-
|
|
41
|
-
lazySignal()
|
|
42
|
-
})
|
|
43
|
-
|
|
44
|
-
expect(mockFn).toHaveBeenCalled()
|
|
45
|
-
})
|
|
46
|
-
|
|
47
|
-
test('should init lazily and only once', async () => {
|
|
48
|
-
const initCallFn = vi.fn()
|
|
49
|
-
const registerEffectValue = vi.fn<[number]>()
|
|
50
|
-
|
|
51
|
-
let value!: Signal<number>
|
|
52
|
-
const outerSignal = signal(0)
|
|
53
|
-
let innerSignal!: WritableSignal<number>
|
|
54
|
-
|
|
55
|
-
TestBed.runInInjectionContext(() => {
|
|
56
|
-
value = lazySignalInitializer(() => {
|
|
57
|
-
initCallFn()
|
|
58
|
-
innerSignal = signal(0)
|
|
59
|
-
|
|
60
|
-
void outerSignal()
|
|
61
|
-
|
|
62
|
-
return innerSignal
|
|
63
|
-
})
|
|
64
|
-
|
|
65
|
-
effect(() => registerEffectValue(value()))
|
|
66
|
-
})
|
|
67
|
-
|
|
68
|
-
value()
|
|
69
|
-
|
|
70
|
-
await flushQueue()
|
|
71
|
-
|
|
72
|
-
expect(outerSignal).toBeDefined()
|
|
73
|
-
expect(innerSignal).toBeDefined()
|
|
74
|
-
|
|
75
|
-
expect(initCallFn).toHaveBeenCalledTimes(1)
|
|
76
|
-
|
|
77
|
-
innerSignal.set(1)
|
|
78
|
-
await flushQueue()
|
|
79
|
-
outerSignal.set(2)
|
|
80
|
-
await flushQueue()
|
|
81
|
-
|
|
82
|
-
expect(initCallFn).toHaveBeenCalledTimes(1)
|
|
83
|
-
expect(registerEffectValue).toHaveBeenCalledTimes(2)
|
|
84
|
-
})
|
|
85
|
-
|
|
86
|
-
test('should init lazily', async () => {
|
|
87
|
-
@Component({
|
|
88
|
-
standalone: true,
|
|
89
|
-
template: `{{ subscribed }}`,
|
|
90
|
-
})
|
|
91
|
-
class Test {
|
|
92
|
-
subscribed = false
|
|
93
|
-
|
|
94
|
-
lazySignal = lazySignalInitializer(() => {
|
|
95
|
-
this.subscribed = true
|
|
96
|
-
return signal('value')
|
|
97
|
-
})
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
const fixture = TestBed.createComponent(Test)
|
|
101
|
-
const { debugElement } = fixture
|
|
102
|
-
fixture.detectChanges()
|
|
103
|
-
|
|
104
|
-
expect(debugElement.nativeElement.textContent).toBe('false')
|
|
105
|
-
|
|
106
|
-
await new Promise(setImmediate)
|
|
107
|
-
|
|
108
|
-
fixture.detectChanges()
|
|
109
|
-
|
|
110
|
-
expect(debugElement.nativeElement.textContent).toBe('true')
|
|
111
|
-
})
|
|
112
|
-
|
|
113
|
-
test('should support required signal input', () => {
|
|
114
|
-
@Component({
|
|
115
|
-
standalone: true,
|
|
116
|
-
template: `{{ subscribed }}`,
|
|
117
|
-
})
|
|
118
|
-
class Test {
|
|
119
|
-
readonly title = input.required<string>()
|
|
120
|
-
subscribed = false
|
|
121
|
-
|
|
122
|
-
lazySignal = lazySignalInitializer(() => {
|
|
123
|
-
return signal(this.title())
|
|
124
|
-
})
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
const fixture = TestBed.createComponent(Test)
|
|
128
|
-
setFixtureSignalInputs(fixture, { title: 'newValue' })
|
|
129
|
-
})
|
|
130
|
-
})
|
package/src/create-base-query.ts
DELETED
|
@@ -1,116 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
DestroyRef,
|
|
3
|
-
Injector,
|
|
4
|
-
NgZone,
|
|
5
|
-
computed,
|
|
6
|
-
effect,
|
|
7
|
-
inject,
|
|
8
|
-
runInInjectionContext,
|
|
9
|
-
signal,
|
|
10
|
-
untracked,
|
|
11
|
-
} from '@angular/core'
|
|
12
|
-
import { notifyManager } from '@tanstack/query-core'
|
|
13
|
-
import { signalProxy } from './signal-proxy'
|
|
14
|
-
import { shouldThrowError } from './util'
|
|
15
|
-
import { lazyInit } from './util/lazy-init/lazy-init'
|
|
16
|
-
import type {
|
|
17
|
-
QueryClient,
|
|
18
|
-
QueryKey,
|
|
19
|
-
QueryObserver,
|
|
20
|
-
QueryObserverResult,
|
|
21
|
-
} from '@tanstack/query-core'
|
|
22
|
-
import type { CreateBaseQueryOptions, CreateBaseQueryResult } from './types'
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* Base implementation for `injectQuery` and `injectInfiniteQuery`.
|
|
26
|
-
*/
|
|
27
|
-
export function createBaseQuery<
|
|
28
|
-
TQueryFnData,
|
|
29
|
-
TError,
|
|
30
|
-
TData,
|
|
31
|
-
TQueryData,
|
|
32
|
-
TQueryKey extends QueryKey,
|
|
33
|
-
>(
|
|
34
|
-
optionsFn: (
|
|
35
|
-
client: QueryClient,
|
|
36
|
-
) => CreateBaseQueryOptions<
|
|
37
|
-
TQueryFnData,
|
|
38
|
-
TError,
|
|
39
|
-
TData,
|
|
40
|
-
TQueryData,
|
|
41
|
-
TQueryKey
|
|
42
|
-
>,
|
|
43
|
-
Observer: typeof QueryObserver,
|
|
44
|
-
queryClient: QueryClient,
|
|
45
|
-
): CreateBaseQueryResult<TData, TError> {
|
|
46
|
-
const injector = inject(Injector)
|
|
47
|
-
const ngZone = inject(NgZone)
|
|
48
|
-
|
|
49
|
-
return lazyInit(() => {
|
|
50
|
-
return runInInjectionContext(injector, () => {
|
|
51
|
-
const destroyRef = inject(DestroyRef)
|
|
52
|
-
/**
|
|
53
|
-
* Signal that has the default options from query client applied
|
|
54
|
-
* computed() is used so signals can be inserted into the options
|
|
55
|
-
* making it reactive. Wrapping options in a function ensures embedded expressions
|
|
56
|
-
* are preserved and can keep being applied after signal changes
|
|
57
|
-
*/
|
|
58
|
-
const defaultedOptionsSignal = computed(() => {
|
|
59
|
-
const defaultedOptions = queryClient.defaultQueryOptions(
|
|
60
|
-
optionsFn(queryClient),
|
|
61
|
-
)
|
|
62
|
-
defaultedOptions._optimisticResults = 'optimistic'
|
|
63
|
-
return defaultedOptions
|
|
64
|
-
})
|
|
65
|
-
|
|
66
|
-
const observer = new Observer<
|
|
67
|
-
TQueryFnData,
|
|
68
|
-
TError,
|
|
69
|
-
TData,
|
|
70
|
-
TQueryData,
|
|
71
|
-
TQueryKey
|
|
72
|
-
>(queryClient, defaultedOptionsSignal())
|
|
73
|
-
|
|
74
|
-
const resultSignal = signal(
|
|
75
|
-
observer.getOptimisticResult(defaultedOptionsSignal()),
|
|
76
|
-
)
|
|
77
|
-
|
|
78
|
-
effect(() => {
|
|
79
|
-
const defaultedOptions = defaultedOptionsSignal()
|
|
80
|
-
observer.setOptions(defaultedOptions, {
|
|
81
|
-
// Do not notify on updates because of changes in the options because
|
|
82
|
-
// these changes should already be reflected in the optimistic result.
|
|
83
|
-
listeners: false,
|
|
84
|
-
})
|
|
85
|
-
untracked(() => {
|
|
86
|
-
resultSignal.set(observer.getOptimisticResult(defaultedOptions))
|
|
87
|
-
})
|
|
88
|
-
})
|
|
89
|
-
|
|
90
|
-
// observer.trackResult is not used as this optimization is not needed for Angular
|
|
91
|
-
const unsubscribe = observer.subscribe(
|
|
92
|
-
notifyManager.batchCalls(
|
|
93
|
-
(state: QueryObserverResult<TData, TError>) => {
|
|
94
|
-
ngZone.run(() => {
|
|
95
|
-
if (
|
|
96
|
-
state.isError &&
|
|
97
|
-
!state.isFetching &&
|
|
98
|
-
// !isRestoring() && // todo: enable when client persistence is implemented
|
|
99
|
-
shouldThrowError(observer.options.throwOnError, [
|
|
100
|
-
state.error,
|
|
101
|
-
observer.getCurrentQuery(),
|
|
102
|
-
])
|
|
103
|
-
) {
|
|
104
|
-
throw state.error
|
|
105
|
-
}
|
|
106
|
-
resultSignal.set(state)
|
|
107
|
-
})
|
|
108
|
-
},
|
|
109
|
-
),
|
|
110
|
-
)
|
|
111
|
-
destroyRef.onDestroy(unsubscribe)
|
|
112
|
-
|
|
113
|
-
return signalProxy(resultSignal) as CreateBaseQueryResult<TData, TError>
|
|
114
|
-
})
|
|
115
|
-
})
|
|
116
|
-
}
|
package/src/index.ts
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
/* istanbul ignore file */
|
|
2
|
-
|
|
3
|
-
// Re-export core
|
|
4
|
-
export * from '@tanstack/query-core'
|
|
5
|
-
|
|
6
|
-
export * from './types'
|
|
7
|
-
|
|
8
|
-
export type {
|
|
9
|
-
DefinedInitialDataOptions,
|
|
10
|
-
UndefinedInitialDataOptions,
|
|
11
|
-
} from './query-options'
|
|
12
|
-
export { queryOptions } from './query-options'
|
|
13
|
-
|
|
14
|
-
export { infiniteQueryOptions } from './infinite-query-options'
|
|
15
|
-
|
|
16
|
-
export * from './inject-infinite-query'
|
|
17
|
-
export * from './inject-is-fetching'
|
|
18
|
-
export * from './inject-is-mutating'
|
|
19
|
-
export * from './inject-mutation'
|
|
20
|
-
export * from './inject-mutation-state'
|
|
21
|
-
export * from './inject-queries'
|
|
22
|
-
export * from './inject-query'
|
|
23
|
-
export { injectQueryClient, provideQueryClient } from './inject-query-client'
|
|
24
|
-
export { provideAngularQuery } from './providers'
|
|
@@ -1,118 +0,0 @@
|
|
|
1
|
-
import type { DataTag } from '@tanstack/query-core'
|
|
2
|
-
import type { InfiniteData } from '@tanstack/query-core'
|
|
3
|
-
import type { CreateInfiniteQueryOptions } from './types'
|
|
4
|
-
import type { DefaultError, QueryKey } from '@tanstack/query-core'
|
|
5
|
-
|
|
6
|
-
export type UndefinedInitialDataInfiniteOptions<
|
|
7
|
-
TQueryFnData,
|
|
8
|
-
TError = DefaultError,
|
|
9
|
-
TData = InfiniteData<TQueryFnData>,
|
|
10
|
-
TQueryKey extends QueryKey = QueryKey,
|
|
11
|
-
TPageParam = unknown,
|
|
12
|
-
> = CreateInfiniteQueryOptions<
|
|
13
|
-
TQueryFnData,
|
|
14
|
-
TError,
|
|
15
|
-
TData,
|
|
16
|
-
TQueryFnData,
|
|
17
|
-
TQueryKey,
|
|
18
|
-
TPageParam
|
|
19
|
-
> & {
|
|
20
|
-
initialData?: undefined
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
type NonUndefinedGuard<T> = T extends undefined ? never : T
|
|
24
|
-
|
|
25
|
-
export type DefinedInitialDataInfiniteOptions<
|
|
26
|
-
TQueryFnData,
|
|
27
|
-
TError = DefaultError,
|
|
28
|
-
TData = InfiniteData<TQueryFnData>,
|
|
29
|
-
TQueryKey extends QueryKey = QueryKey,
|
|
30
|
-
TPageParam = unknown,
|
|
31
|
-
> = CreateInfiniteQueryOptions<
|
|
32
|
-
TQueryFnData,
|
|
33
|
-
TError,
|
|
34
|
-
TData,
|
|
35
|
-
TQueryFnData,
|
|
36
|
-
TQueryKey,
|
|
37
|
-
TPageParam
|
|
38
|
-
> & {
|
|
39
|
-
initialData:
|
|
40
|
-
| NonUndefinedGuard<InfiniteData<TQueryFnData, TPageParam>>
|
|
41
|
-
| (() => NonUndefinedGuard<InfiniteData<TQueryFnData, TPageParam>>)
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* Allows to share and re-use infinite query options in a type-safe way.
|
|
46
|
-
*
|
|
47
|
-
* The `queryKey` will be tagged with the type from `queryFn`.
|
|
48
|
-
* @param options - The infinite query options to tag with the type from `queryFn`.
|
|
49
|
-
* @returns The tagged infinite query options.
|
|
50
|
-
* @public
|
|
51
|
-
*/
|
|
52
|
-
export function infiniteQueryOptions<
|
|
53
|
-
TQueryFnData,
|
|
54
|
-
TError = DefaultError,
|
|
55
|
-
TData = InfiniteData<TQueryFnData>,
|
|
56
|
-
TQueryKey extends QueryKey = QueryKey,
|
|
57
|
-
TPageParam = unknown,
|
|
58
|
-
>(
|
|
59
|
-
options: UndefinedInitialDataInfiniteOptions<
|
|
60
|
-
TQueryFnData,
|
|
61
|
-
TError,
|
|
62
|
-
TData,
|
|
63
|
-
TQueryKey,
|
|
64
|
-
TPageParam
|
|
65
|
-
>,
|
|
66
|
-
): UndefinedInitialDataInfiniteOptions<
|
|
67
|
-
TQueryFnData,
|
|
68
|
-
TError,
|
|
69
|
-
TData,
|
|
70
|
-
TQueryKey,
|
|
71
|
-
TPageParam
|
|
72
|
-
> & {
|
|
73
|
-
queryKey: DataTag<TQueryKey, InfiniteData<TQueryFnData>>
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
/**
|
|
77
|
-
* Allows to share and re-use infinite query options in a type-safe way.
|
|
78
|
-
*
|
|
79
|
-
* The `queryKey` will be tagged with the type from `queryFn`.
|
|
80
|
-
* @param options - The infinite query options to tag with the type from `queryFn`.
|
|
81
|
-
* @returns The tagged infinite query options.
|
|
82
|
-
* @public
|
|
83
|
-
*/
|
|
84
|
-
export function infiniteQueryOptions<
|
|
85
|
-
TQueryFnData,
|
|
86
|
-
TError = DefaultError,
|
|
87
|
-
TData = InfiniteData<TQueryFnData>,
|
|
88
|
-
TQueryKey extends QueryKey = QueryKey,
|
|
89
|
-
TPageParam = unknown,
|
|
90
|
-
>(
|
|
91
|
-
options: DefinedInitialDataInfiniteOptions<
|
|
92
|
-
TQueryFnData,
|
|
93
|
-
TError,
|
|
94
|
-
TData,
|
|
95
|
-
TQueryKey,
|
|
96
|
-
TPageParam
|
|
97
|
-
>,
|
|
98
|
-
): DefinedInitialDataInfiniteOptions<
|
|
99
|
-
TQueryFnData,
|
|
100
|
-
TError,
|
|
101
|
-
TData,
|
|
102
|
-
TQueryKey,
|
|
103
|
-
TPageParam
|
|
104
|
-
> & {
|
|
105
|
-
queryKey: DataTag<TQueryKey, InfiniteData<TQueryFnData>>
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
/**
|
|
109
|
-
* Allows to share and re-use infinite query options in a type-safe way.
|
|
110
|
-
*
|
|
111
|
-
* The `queryKey` will be tagged with the type from `queryFn`.
|
|
112
|
-
* @param options - The infinite query options to tag with the type from `queryFn`.
|
|
113
|
-
* @returns The tagged infinite query options.
|
|
114
|
-
* @public
|
|
115
|
-
*/
|
|
116
|
-
export function infiniteQueryOptions(options: unknown) {
|
|
117
|
-
return options
|
|
118
|
-
}
|
|
@@ -1,125 +0,0 @@
|
|
|
1
|
-
import { InfiniteQueryObserver } from '@tanstack/query-core'
|
|
2
|
-
import { createBaseQuery } from './create-base-query'
|
|
3
|
-
import { injectQueryClient } from './inject-query-client'
|
|
4
|
-
import { assertInjector } from './util/assert-injector/assert-injector'
|
|
5
|
-
import type { Injector } from '@angular/core'
|
|
6
|
-
import type {
|
|
7
|
-
DefaultError,
|
|
8
|
-
InfiniteData,
|
|
9
|
-
QueryClient,
|
|
10
|
-
QueryKey,
|
|
11
|
-
QueryObserver,
|
|
12
|
-
} from '@tanstack/query-core'
|
|
13
|
-
import type {
|
|
14
|
-
CreateInfiniteQueryOptions,
|
|
15
|
-
CreateInfiniteQueryResult,
|
|
16
|
-
DefinedCreateInfiniteQueryResult,
|
|
17
|
-
} from './types'
|
|
18
|
-
import type {
|
|
19
|
-
DefinedInitialDataInfiniteOptions,
|
|
20
|
-
UndefinedInitialDataInfiniteOptions,
|
|
21
|
-
} from './infinite-query-options'
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* Injects an infinite query: a declarative dependency on an asynchronous source of data that is tied to a unique key.
|
|
25
|
-
* Infinite queries can additively "load more" data onto an existing set of data or "infinite scroll"
|
|
26
|
-
* @param optionsFn - A function that returns infinite query options.
|
|
27
|
-
* @param injector - The Angular injector to use.
|
|
28
|
-
* @returns The infinite query result.
|
|
29
|
-
* @public
|
|
30
|
-
*/
|
|
31
|
-
export function injectInfiniteQuery<
|
|
32
|
-
TQueryFnData,
|
|
33
|
-
TError = DefaultError,
|
|
34
|
-
TData = InfiniteData<TQueryFnData>,
|
|
35
|
-
TQueryKey extends QueryKey = QueryKey,
|
|
36
|
-
TPageParam = unknown,
|
|
37
|
-
>(
|
|
38
|
-
optionsFn: (
|
|
39
|
-
client: QueryClient,
|
|
40
|
-
) => UndefinedInitialDataInfiniteOptions<
|
|
41
|
-
TQueryFnData,
|
|
42
|
-
TError,
|
|
43
|
-
TData,
|
|
44
|
-
TQueryKey,
|
|
45
|
-
TPageParam
|
|
46
|
-
>,
|
|
47
|
-
injector?: Injector,
|
|
48
|
-
): CreateInfiniteQueryResult<TData, TError>
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
* Injects an infinite query: a declarative dependency on an asynchronous source of data that is tied to a unique key.
|
|
52
|
-
* Infinite queries can additively "load more" data onto an existing set of data or "infinite scroll"
|
|
53
|
-
* @param optionsFn - A function that returns infinite query options.
|
|
54
|
-
* @param injector - The Angular injector to use.
|
|
55
|
-
* @returns The infinite query result.
|
|
56
|
-
* @public
|
|
57
|
-
*/
|
|
58
|
-
export function injectInfiniteQuery<
|
|
59
|
-
TQueryFnData,
|
|
60
|
-
TError = DefaultError,
|
|
61
|
-
TData = InfiniteData<TQueryFnData>,
|
|
62
|
-
TQueryKey extends QueryKey = QueryKey,
|
|
63
|
-
TPageParam = unknown,
|
|
64
|
-
>(
|
|
65
|
-
optionsFn: (
|
|
66
|
-
client: QueryClient,
|
|
67
|
-
) => DefinedInitialDataInfiniteOptions<
|
|
68
|
-
TQueryFnData,
|
|
69
|
-
TError,
|
|
70
|
-
TData,
|
|
71
|
-
TQueryKey,
|
|
72
|
-
TPageParam
|
|
73
|
-
>,
|
|
74
|
-
injector?: Injector,
|
|
75
|
-
): DefinedCreateInfiniteQueryResult<TData, TError>
|
|
76
|
-
|
|
77
|
-
/**
|
|
78
|
-
* Injects an infinite query: a declarative dependency on an asynchronous source of data that is tied to a unique key.
|
|
79
|
-
* Infinite queries can additively "load more" data onto an existing set of data or "infinite scroll"
|
|
80
|
-
* @param optionsFn - A function that returns infinite query options.
|
|
81
|
-
* @param injector - The Angular injector to use.
|
|
82
|
-
* @returns The infinite query result.
|
|
83
|
-
* @public
|
|
84
|
-
*/
|
|
85
|
-
export function injectInfiniteQuery<
|
|
86
|
-
TQueryFnData,
|
|
87
|
-
TError = DefaultError,
|
|
88
|
-
TData = InfiniteData<TQueryFnData>,
|
|
89
|
-
TQueryKey extends QueryKey = QueryKey,
|
|
90
|
-
TPageParam = unknown,
|
|
91
|
-
>(
|
|
92
|
-
optionsFn: (
|
|
93
|
-
client: QueryClient,
|
|
94
|
-
) => CreateInfiniteQueryOptions<
|
|
95
|
-
TQueryFnData,
|
|
96
|
-
TError,
|
|
97
|
-
TData,
|
|
98
|
-
TQueryFnData,
|
|
99
|
-
TQueryKey,
|
|
100
|
-
TPageParam
|
|
101
|
-
>,
|
|
102
|
-
injector?: Injector,
|
|
103
|
-
): CreateInfiniteQueryResult<TData, TError>
|
|
104
|
-
|
|
105
|
-
/**
|
|
106
|
-
* Injects an infinite query: a declarative dependency on an asynchronous source of data that is tied to a unique key.
|
|
107
|
-
* Infinite queries can additively "load more" data onto an existing set of data or "infinite scroll"
|
|
108
|
-
* @param optionsFn - A function that returns infinite query options.
|
|
109
|
-
* @param injector - The Angular injector to use.
|
|
110
|
-
* @returns The infinite query result.
|
|
111
|
-
* @public
|
|
112
|
-
*/
|
|
113
|
-
export function injectInfiniteQuery(
|
|
114
|
-
optionsFn: (client: QueryClient) => CreateInfiniteQueryOptions,
|
|
115
|
-
injector?: Injector,
|
|
116
|
-
) {
|
|
117
|
-
return assertInjector(injectInfiniteQuery, injector, () => {
|
|
118
|
-
const queryClient = injectQueryClient()
|
|
119
|
-
return createBaseQuery(
|
|
120
|
-
optionsFn,
|
|
121
|
-
InfiniteQueryObserver as typeof QueryObserver,
|
|
122
|
-
queryClient,
|
|
123
|
-
)
|
|
124
|
-
})
|
|
125
|
-
}
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import { DestroyRef, NgZone, inject, signal } from '@angular/core'
|
|
2
|
-
import { type QueryFilters, notifyManager } from '@tanstack/query-core'
|
|
3
|
-
import { assertInjector } from './util/assert-injector/assert-injector'
|
|
4
|
-
import { injectQueryClient } from './inject-query-client'
|
|
5
|
-
import type { Injector, Signal } from '@angular/core'
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Injects a signal that tracks the number of queries that your application is loading or
|
|
9
|
-
* fetching in the background.
|
|
10
|
-
*
|
|
11
|
-
* Can be used for app-wide loading indicators
|
|
12
|
-
* @param filters - The filters to apply to the query.
|
|
13
|
-
* @param injector - The Angular injector to use.
|
|
14
|
-
* @returns signal with number of loading or fetching queries.
|
|
15
|
-
* @public
|
|
16
|
-
*/
|
|
17
|
-
export function injectIsFetching(
|
|
18
|
-
filters?: QueryFilters,
|
|
19
|
-
injector?: Injector,
|
|
20
|
-
): Signal<number> {
|
|
21
|
-
return assertInjector(injectIsFetching, injector, () => {
|
|
22
|
-
const queryClient = injectQueryClient()
|
|
23
|
-
const destroyRef = inject(DestroyRef)
|
|
24
|
-
const ngZone = inject(NgZone)
|
|
25
|
-
|
|
26
|
-
const cache = queryClient.getQueryCache()
|
|
27
|
-
// isFetching is the prev value initialized on mount *
|
|
28
|
-
let isFetching = queryClient.isFetching(filters)
|
|
29
|
-
|
|
30
|
-
const result = signal(isFetching)
|
|
31
|
-
|
|
32
|
-
const unsubscribe = cache.subscribe(
|
|
33
|
-
notifyManager.batchCalls(() => {
|
|
34
|
-
const newIsFetching = queryClient.isFetching(filters)
|
|
35
|
-
if (isFetching !== newIsFetching) {
|
|
36
|
-
// * and update with each change
|
|
37
|
-
isFetching = newIsFetching
|
|
38
|
-
ngZone.run(() => {
|
|
39
|
-
result.set(isFetching)
|
|
40
|
-
})
|
|
41
|
-
}
|
|
42
|
-
}),
|
|
43
|
-
)
|
|
44
|
-
|
|
45
|
-
destroyRef.onDestroy(unsubscribe)
|
|
46
|
-
|
|
47
|
-
return result
|
|
48
|
-
})
|
|
49
|
-
}
|