@tanstack/angular-query-experimental 5.73.3 → 5.74.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.
@@ -1,78 +0,0 @@
1
- /* eslint-disable cspell/spellchecker */
2
- /**
3
- * The code in this file is adapted from NG Extension Platform at https://ngxtension.netlify.app.
4
- *
5
- * Original Author: Chau Tran
6
- *
7
- * NG Extension Platform is an open-source project licensed under the MIT license.
8
- *
9
- * For more information about the original code, see
10
- * https://github.com/nartc/ngxtension-platform
11
- */
12
- /* eslint-enable */
13
-
14
- import {
15
- InjectionToken,
16
- Injector,
17
- inject,
18
- provideExperimentalZonelessChangeDetection,
19
- runInInjectionContext,
20
- } from '@angular/core'
21
- import { TestBed } from '@angular/core/testing'
22
- import { assertInjector } from './assert-injector'
23
-
24
- describe('assertInjector', () => {
25
- const token = new InjectionToken('token', {
26
- factory: () => 1,
27
- })
28
-
29
- function injectDummy(injector?: Injector) {
30
- injector = assertInjector(injectDummy, injector)
31
- return runInInjectionContext(injector, () => inject(token))
32
- }
33
-
34
- function injectDummyTwo(injector?: Injector) {
35
- return assertInjector(injectDummyTwo, injector, () => inject(token) + 1)
36
- }
37
-
38
- it('given no custom injector, when run in injection context, then return value', () => {
39
- TestBed.configureTestingModule({
40
- providers: [provideExperimentalZonelessChangeDetection()],
41
- })
42
- TestBed.runInInjectionContext(() => {
43
- const value = injectDummy()
44
- const valueTwo = injectDummyTwo()
45
- expect(value).toEqual(1)
46
- expect(valueTwo).toEqual(2)
47
- })
48
- })
49
-
50
- it('given no custom injector, when run outside injection context, then throw', () => {
51
- expect(() => injectDummy()).toThrowError(
52
- /injectDummy\(\) can only be used within an injection context/i,
53
- )
54
- expect(() => injectDummyTwo()).toThrowError(
55
- /injectDummyTwo\(\) can only be used within an injection context/i,
56
- )
57
- })
58
-
59
- it('given a custom injector, when run in that injector context without providing number, then throw', () => {
60
- expect(() => injectDummy(Injector.create({ providers: [] }))).toThrowError(
61
- /No provider for InjectionToken/i,
62
- )
63
- expect(() =>
64
- injectDummyTwo(Injector.create({ providers: [] })),
65
- ).toThrowError(/No provider for InjectionToken/i)
66
- })
67
-
68
- it('given a custom injector, when run in that injector context and providing number, then return value', () => {
69
- const value = injectDummy(
70
- Injector.create({ providers: [{ provide: token, useValue: 2 }] }),
71
- )
72
- const valueTwo = injectDummyTwo(
73
- Injector.create({ providers: [{ provide: token, useValue: 2 }] }),
74
- )
75
- expect(value).toEqual(2)
76
- expect(valueTwo).toEqual(3)
77
- })
78
- })
@@ -1,83 +0,0 @@
1
- /* eslint-disable cspell/spellchecker */
2
- /**
3
- * The code in this file is adapted from NG Extension Platform at https://ngxtension.netlify.app.
4
- *
5
- * Original Author: Chau Tran
6
- *
7
- * NG Extension Platform is an open-source project licensed under the MIT license.
8
- *
9
- * For more information about the original code, see
10
- * https://github.com/nartc/ngxtension-platform
11
- */
12
- /* eslint-enable */
13
-
14
- import {
15
- Injector,
16
- assertInInjectionContext,
17
- inject,
18
- runInInjectionContext,
19
- } from '@angular/core'
20
-
21
- /**
22
- * `assertInjector` extends `assertInInjectionContext` with an optional `Injector`
23
- * After assertion, `assertInjector` runs the `runner` function with the guaranteed `Injector`
24
- * whether it is the default `Injector` within the current **Injection Context**
25
- * or the custom `Injector` that was passed in.
26
- * @template {() => any} Runner - Runner is a function that can return anything
27
- * @param fn - the Function to pass in `assertInInjectionContext`
28
- * @param injector - the optional "custom" Injector
29
- * @param runner - the runner fn
30
- * @returns result - returns the result of the Runner
31
- * @example
32
- * ```ts
33
- * function injectValue(injector?: Injector) {
34
- * return assertInjector(injectValue, injector, () => 'value');
35
- * }
36
- *
37
- * injectValue(); // string
38
- * ```
39
- */
40
- export function assertInjector<TRunner extends () => any>(
41
- fn: Function,
42
- injector: Injector | undefined | null,
43
- runner: TRunner,
44
- ): ReturnType<TRunner>
45
- /**
46
- * `assertInjector` extends `assertInInjectionContext` with an optional `Injector`
47
- * After assertion, `assertInjector` returns a guaranteed `Injector` whether it is the default `Injector`
48
- * within the current **Injection Context** or the custom `Injector` that was passed in.
49
- * @param fn - the Function to pass in `assertInInjectionContext`
50
- * @param injector - the optional "custom" Injector
51
- * @returns Injector
52
- * @example
53
- * ```ts
54
- * function injectDestroy(injector?: Injector) {
55
- * injector = assertInjector(injectDestroy, injector);
56
- *
57
- * return runInInjectionContext(injector, () => {
58
- * // code
59
- * })
60
- * }
61
- * ```
62
- */
63
- export function assertInjector(
64
- fn: Function,
65
- injector: Injector | undefined | null,
66
- ): Injector
67
- /**
68
- * @param fn - the Function to pass in `assertInInjectionContext`
69
- * @param injector - the optional "custom" Injector
70
- * @param runner - the runner fn
71
- * @returns any
72
- */
73
- export function assertInjector(
74
- fn: Function,
75
- injector: Injector | undefined | null,
76
- runner?: () => any,
77
- ) {
78
- !injector && assertInInjectionContext(fn)
79
- const assertedInjector = injector ?? inject(Injector)
80
-
81
- if (!runner) return assertedInjector
82
- return runInInjectionContext(assertedInjector, runner)
83
- }