static-injector 5.0.2 → 6.0.0
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/import/change_detection/scheduling/zoneless_scheduling.d.ts +37 -0
- package/import/change_detection/scheduling/zoneless_scheduling_impl.d.ts +16 -0
- package/import/core_reactivity_export_internal.d.ts +17 -0
- package/import/di/contextual.d.ts +36 -0
- package/{typings → import}/di/create_injector.d.ts +1 -1
- package/{typings → import}/di/forward_ref.d.ts +2 -2
- package/import/di/index.d.ts +3 -0
- package/{typings → import}/di/initializer_token.d.ts +8 -1
- package/{typings → import}/di/inject_switch.d.ts +2 -2
- package/{typings → import}/di/injectable.d.ts +2 -2
- package/{typings → import}/di/injection_token.d.ts +3 -4
- package/{typings → import}/di/injector.d.ts +1 -1
- package/{typings → import}/di/injector_compatibility.d.ts +1 -1
- package/{typings → import}/di/injector_marker.d.ts +1 -1
- package/{typings → import}/di/injector_token.d.ts +1 -1
- package/{typings → import}/di/interface/defs.d.ts +1 -1
- package/{typings → import}/di/interface/injector.d.ts +1 -1
- package/{typings → import}/di/interface/provider.d.ts +1 -1
- package/{typings → import}/di/internal_tokens.d.ts +1 -1
- package/{typings → import}/di/metadata.d.ts +5 -9
- package/{typings → import}/di/null_injector.d.ts +1 -1
- package/{typings → import}/di/provider_collection.d.ts +31 -3
- package/{typings → import}/di/provider_token.d.ts +1 -1
- package/{typings → import}/di/r3_injector.d.ts +2 -2
- package/{typings → import}/di/scope.d.ts +1 -1
- package/{typings → import}/di.d.ts +1 -1
- package/import/error_handler.d.ts +45 -0
- package/{typings → import}/errors.d.ts +9 -7
- package/import/index.d.ts +37 -0
- package/{typings → import}/interface/lifecycle_hooks.d.ts +1 -1
- package/{typings → import}/interface/type.d.ts +4 -9
- package/import/linker/destroy_ref.d.ts +44 -0
- package/import/pending_tasks.d.ts +78 -0
- package/{typings → import}/render3/definition_factory.d.ts +1 -1
- package/{typings → import}/render3/errors_di.d.ts +1 -1
- package/{typings → import}/render3/fields.d.ts +1 -1
- package/{typings → import}/render3/instructions/di.d.ts +1 -1
- package/import/render3/reactivity/api.d.ts +27 -0
- package/import/render3/reactivity/asserts.d.ts +16 -0
- package/import/render3/reactivity/computed.d.ts +25 -0
- package/import/render3/reactivity/effect.d.ts +121 -0
- package/import/render3/reactivity/linked_signal.d.ts +33 -0
- package/import/render3/reactivity/microtask_effect.d.ts +21 -0
- package/import/render3/reactivity/patch.d.ts +11 -0
- package/import/render3/reactivity/root_effect_scheduler.d.ts +54 -0
- package/import/render3/reactivity/signal.d.ts +61 -0
- package/import/render3/reactivity/untracked.d.ts +12 -0
- package/import/resource/api.d.ts +219 -0
- package/{es2022/di/injectable.js → import/resource/index.d.ts} +3 -2
- package/import/resource/resource.d.ts +89 -0
- package/import/util/callback_scheduler.d.ts +35 -0
- package/{typings → import}/util/closure.d.ts +1 -1
- package/{typings → import}/util/decorators.d.ts +3 -3
- package/{typings → import}/util/empty.d.ts +1 -1
- package/{es2022/di/provider_token.js → import/util/noop.d.ts} +2 -2
- package/{typings → import}/util/property.d.ts +1 -1
- package/{typings → import}/util/stringify.d.ts +1 -1
- package/index.js +2349 -0
- package/index.js.map +7 -0
- package/index.mjs +2258 -0
- package/index.mjs.map +7 -0
- package/package.json +19 -10
- package/primitives/signals/index.d.ts +15 -0
- package/primitives/signals/src/computed.d.ts +55 -0
- package/primitives/signals/src/equality.d.ts +15 -0
- package/primitives/signals/src/errors.d.ts +10 -0
- package/primitives/signals/src/graph.d.ts +182 -0
- package/primitives/signals/src/linked_signal.d.ts +72 -0
- package/primitives/signals/src/signal.d.ts +29 -0
- package/primitives/signals/src/watch.d.ts +43 -0
- package/{es2022/di/injector_marker.js → primitives/signals/src/weak_ref.d.ts} +2 -2
- package/readme.md +17 -13
- package/commonjs/index.js +0 -1586
- package/es2022/di/create_injector.js +0 -32
- package/es2022/di/forward_ref.js +0 -80
- package/es2022/di/index.js +0 -1
- package/es2022/di/initializer_token.js +0 -15
- package/es2022/di/inject_switch.js +0 -51
- package/es2022/di/injection_token.js +0 -93
- package/es2022/di/injector.js +0 -60
- package/es2022/di/injector_compatibility.js +0 -265
- package/es2022/di/injector_token.js +0 -20
- package/es2022/di/interface/defs.js +0 -110
- package/es2022/di/interface/injector.js +0 -26
- package/es2022/di/interface/provider.js +0 -10
- package/es2022/di/internal_tokens.js +0 -9
- package/es2022/di/metadata.js +0 -48
- package/es2022/di/null_injector.js +0 -19
- package/es2022/di/provider_collection.js +0 -104
- package/es2022/di/r3_injector.js +0 -449
- package/es2022/di/scope.js +0 -14
- package/es2022/di.js +0 -24
- package/es2022/errors.js +0 -44
- package/es2022/index.js +0 -19
- package/es2022/interface/lifecycle_hooks.js +0 -8
- package/es2022/interface/type.js +0 -21
- package/es2022/render3/definition_factory.js +0 -10
- package/es2022/render3/errors_di.js +0 -13
- package/es2022/render3/fields.js +0 -22
- package/es2022/render3/instructions/di.js +0 -23
- package/es2022/render3/util/stringify_utils.js +0 -38
- package/es2022/util/closure.js +0 -19
- package/es2022/util/decorators.js +0 -31
- package/es2022/util/empty.js +0 -18
- package/es2022/util/property.js +0 -15
- package/es2022/util/stringify.js +0 -45
- package/fesm2022/index.js +0 -1547
- package/typings/di/index.d.ts +0 -1
- package/typings/index.d.ts +0 -18
- package/typings/render3/util/stringify_utils.d.ts +0 -21
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* Copyright Google LLC All Rights Reserved.
|
|
4
4
|
*
|
|
5
5
|
* Use of this source code is governed by an MIT-style license that can be
|
|
6
|
-
* found in the LICENSE file at https://angular.
|
|
6
|
+
* found in the LICENSE file at https://angular.dev/license
|
|
7
7
|
*/
|
|
8
8
|
/**
|
|
9
9
|
* @description
|
|
@@ -31,28 +31,23 @@ export interface AbstractType<T> extends Function {
|
|
|
31
31
|
export interface Type<T> extends Function {
|
|
32
32
|
new (...args: any[]): T;
|
|
33
33
|
}
|
|
34
|
-
export type Mutable<T extends {
|
|
35
|
-
[x: string]: any;
|
|
36
|
-
}, K extends string> = {
|
|
37
|
-
[P in K]: T[P];
|
|
38
|
-
};
|
|
39
34
|
/**
|
|
40
35
|
* Returns a writable type version of type.
|
|
41
36
|
*
|
|
42
37
|
* USAGE:
|
|
43
38
|
* Given:
|
|
44
|
-
* ```
|
|
39
|
+
* ```ts
|
|
45
40
|
* interface Person {readonly name: string}
|
|
46
41
|
* ```
|
|
47
42
|
*
|
|
48
43
|
* We would like to get a read/write version of `Person`.
|
|
49
|
-
* ```
|
|
44
|
+
* ```ts
|
|
50
45
|
* const WritablePerson = Writable<Person>;
|
|
51
46
|
* ```
|
|
52
47
|
*
|
|
53
48
|
* The result is that you can do:
|
|
54
49
|
*
|
|
55
|
-
* ```
|
|
50
|
+
* ```ts
|
|
56
51
|
* const readonlyPerson: Person = {name: 'Marry'};
|
|
57
52
|
* readonlyPerson.name = 'John'; // TypeError
|
|
58
53
|
* (readonlyPerson as WritablePerson).name = 'John'; // OK
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright Google LLC All Rights Reserved.
|
|
4
|
+
*
|
|
5
|
+
* Use of this source code is governed by an MIT-style license that can be
|
|
6
|
+
* found in the LICENSE file at https://angular.dev/license
|
|
7
|
+
*/
|
|
8
|
+
import { EnvironmentInjector } from '../di';
|
|
9
|
+
/**
|
|
10
|
+
* `DestroyRef` lets you set callbacks to run for any cleanup or destruction behavior.
|
|
11
|
+
* The scope of this destruction depends on where `DestroyRef` is injected. If `DestroyRef`
|
|
12
|
+
* is injected in a component or directive, the callbacks run when that component or
|
|
13
|
+
* directive is destroyed. Otherwise the callbacks run when a corresponding injector is destroyed.
|
|
14
|
+
*
|
|
15
|
+
* @publicApi
|
|
16
|
+
*/
|
|
17
|
+
export declare abstract class DestroyRef {
|
|
18
|
+
/**
|
|
19
|
+
* Registers a destroy callback in a given lifecycle scope. Returns a cleanup function that can
|
|
20
|
+
* be invoked to unregister the callback.
|
|
21
|
+
*
|
|
22
|
+
* @usageNotes
|
|
23
|
+
* ### Example
|
|
24
|
+
* ```ts
|
|
25
|
+
* const destroyRef = inject(DestroyRef);
|
|
26
|
+
*
|
|
27
|
+
* // register a destroy callback
|
|
28
|
+
* const unregisterFn = destroyRef.onDestroy(() => doSomethingOnDestroy());
|
|
29
|
+
*
|
|
30
|
+
* // stop the destroy callback from executing if needed
|
|
31
|
+
* unregisterFn();
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
34
|
+
abstract onDestroy(callback: () => void): () => void;
|
|
35
|
+
/**
|
|
36
|
+
* @internal
|
|
37
|
+
* @nocollapse
|
|
38
|
+
*/
|
|
39
|
+
/**
|
|
40
|
+
* @internal
|
|
41
|
+
* @nocollapse
|
|
42
|
+
*/
|
|
43
|
+
static __NG_ENV_ID__: (injector: EnvironmentInjector) => DestroyRef;
|
|
44
|
+
}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright Google LLC All Rights Reserved.
|
|
4
|
+
*
|
|
5
|
+
* Use of this source code is governed by an MIT-style license that can be
|
|
6
|
+
* found in the LICENSE file at https://angular.dev/license
|
|
7
|
+
*/
|
|
8
|
+
import { BehaviorSubject } from 'rxjs';
|
|
9
|
+
import { OnDestroy } from './interface/lifecycle_hooks';
|
|
10
|
+
/**
|
|
11
|
+
* Internal implementation of the pending tasks service.
|
|
12
|
+
*/
|
|
13
|
+
export declare class PendingTasksInternal implements OnDestroy {
|
|
14
|
+
private taskId;
|
|
15
|
+
private pendingTasks;
|
|
16
|
+
private get _hasPendingTasks();
|
|
17
|
+
hasPendingTasks: BehaviorSubject<boolean>;
|
|
18
|
+
add(): number;
|
|
19
|
+
has(taskId: number): boolean;
|
|
20
|
+
remove(taskId: number): void;
|
|
21
|
+
ngOnDestroy(): void;
|
|
22
|
+
/** @nocollapse */
|
|
23
|
+
static ɵprov: unknown;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Service that keeps track of pending tasks contributing to the stableness of Angular
|
|
27
|
+
* application. While several existing Angular services (ex.: `HttpClient`) will internally manage
|
|
28
|
+
* tasks influencing stability, this API gives control over stability to library and application
|
|
29
|
+
* developers for specific cases not covered by Angular internals.
|
|
30
|
+
*
|
|
31
|
+
* The concept of stability comes into play in several important scenarios:
|
|
32
|
+
* - SSR process needs to wait for the application stability before serializing and sending rendered
|
|
33
|
+
* HTML;
|
|
34
|
+
* - tests might want to delay assertions until the application becomes stable;
|
|
35
|
+
*
|
|
36
|
+
* @usageNotes
|
|
37
|
+
* ```ts
|
|
38
|
+
* const pendingTasks = inject(PendingTasks);
|
|
39
|
+
* const taskCleanup = pendingTasks.add();
|
|
40
|
+
* // do work that should block application's stability and then:
|
|
41
|
+
* taskCleanup();
|
|
42
|
+
* ```
|
|
43
|
+
*
|
|
44
|
+
* @publicApi
|
|
45
|
+
* @developerPreview
|
|
46
|
+
*/
|
|
47
|
+
export declare class PendingTasks {
|
|
48
|
+
private internalPendingTasks;
|
|
49
|
+
private scheduler;
|
|
50
|
+
/**
|
|
51
|
+
* Adds a new task that should block application's stability.
|
|
52
|
+
* @returns A cleanup function that removes a task when called.
|
|
53
|
+
*/
|
|
54
|
+
add(): () => void;
|
|
55
|
+
/**
|
|
56
|
+
* Runs an asynchronous function and blocks the application's stability until the function completes.
|
|
57
|
+
*
|
|
58
|
+
* ```ts
|
|
59
|
+
* pendingTasks.run(async () => {
|
|
60
|
+
* const userData = await fetch('/api/user');
|
|
61
|
+
* this.userData.set(userData);
|
|
62
|
+
* });
|
|
63
|
+
* ```
|
|
64
|
+
*
|
|
65
|
+
* Application stability is at least delayed until the next tick after the `run` method resolves
|
|
66
|
+
* so it is safe to make additional updates to application state that would require UI synchronization:
|
|
67
|
+
*
|
|
68
|
+
* ```ts
|
|
69
|
+
* const userData = await pendingTasks.run(() => fetch('/api/user'));
|
|
70
|
+
* this.userData.set(userData);
|
|
71
|
+
* ```
|
|
72
|
+
*
|
|
73
|
+
* @param fn The asynchronous function to execute
|
|
74
|
+
*/
|
|
75
|
+
run<T>(fn: () => Promise<T>): Promise<T>;
|
|
76
|
+
/** @nocollapse */
|
|
77
|
+
static ɵprov: unknown;
|
|
78
|
+
}
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* Copyright Google LLC All Rights Reserved.
|
|
4
4
|
*
|
|
5
5
|
* Use of this source code is governed by an MIT-style license that can be
|
|
6
|
-
* found in the LICENSE file at https://angular.
|
|
6
|
+
* found in the LICENSE file at https://angular.dev/license
|
|
7
7
|
*/
|
|
8
8
|
import { Type } from '../interface/type';
|
|
9
9
|
/**
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* Copyright Google LLC All Rights Reserved.
|
|
4
4
|
*
|
|
5
5
|
* Use of this source code is governed by an MIT-style license that can be
|
|
6
|
-
* found in the LICENSE file at https://angular.
|
|
6
|
+
* found in the LICENSE file at https://angular.dev/license
|
|
7
7
|
*/
|
|
8
8
|
import type { ProviderToken } from '../di';
|
|
9
9
|
/** Throws an error when a token is not found in DI. */
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* Copyright Google LLC All Rights Reserved.
|
|
4
4
|
*
|
|
5
5
|
* Use of this source code is governed by an MIT-style license that can be
|
|
6
|
-
* found in the LICENSE file at https://angular.
|
|
6
|
+
* found in the LICENSE file at https://angular.dev/license
|
|
7
7
|
*/
|
|
8
8
|
export declare const NG_FACTORY_DEF: string;
|
|
9
9
|
/**
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* Copyright Google LLC All Rights Reserved.
|
|
4
4
|
*
|
|
5
5
|
* Use of this source code is governed by an MIT-style license that can be
|
|
6
|
-
* found in the LICENSE file at https://angular.
|
|
6
|
+
* found in the LICENSE file at https://angular.dev/license
|
|
7
7
|
*/
|
|
8
8
|
/**
|
|
9
9
|
* Throws an error indicating that a factory function could not be generated by the compiler for a
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright Google LLC All Rights Reserved.
|
|
4
|
+
*
|
|
5
|
+
* Use of this source code is governed by an MIT-style license that can be
|
|
6
|
+
* found in the LICENSE file at https://angular.dev/license
|
|
7
|
+
*/
|
|
8
|
+
import { SIGNAL } from '@angular/core/primitives/signals';
|
|
9
|
+
/**
|
|
10
|
+
* A reactive value which notifies consumers of any changes.
|
|
11
|
+
*
|
|
12
|
+
* Signals are functions which returns their current value. To access the current value of a signal,
|
|
13
|
+
* call it.
|
|
14
|
+
*
|
|
15
|
+
* Ordinary values can be turned into `Signal`s with the `signal` function.
|
|
16
|
+
*/
|
|
17
|
+
export type Signal<T> = (() => T) & {
|
|
18
|
+
[SIGNAL]: unknown;
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* Checks if the given `value` is a reactive `Signal`.
|
|
22
|
+
*/
|
|
23
|
+
export declare function isSignal(value: unknown): value is Signal<unknown>;
|
|
24
|
+
/**
|
|
25
|
+
* A comparison function which can determine if two values are equal.
|
|
26
|
+
*/
|
|
27
|
+
export type ValueEqualityFn<T> = (a: T, b: T) => boolean;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright Google LLC All Rights Reserved.
|
|
4
|
+
*
|
|
5
|
+
* Use of this source code is governed by an MIT-style license that can be
|
|
6
|
+
* found in the LICENSE file at https://angular.dev/license
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* Asserts that the current stack frame is not within a reactive context. Useful
|
|
10
|
+
* to disallow certain code from running inside a reactive context (see {@link toSignal}).
|
|
11
|
+
*
|
|
12
|
+
* @param debugFn a reference to the function making the assertion (used for the error message).
|
|
13
|
+
*
|
|
14
|
+
* @publicApi
|
|
15
|
+
*/
|
|
16
|
+
export declare function assertNotInReactiveContext(debugFn: Function, extraContext?: string): void;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright Google LLC All Rights Reserved.
|
|
4
|
+
*
|
|
5
|
+
* Use of this source code is governed by an MIT-style license that can be
|
|
6
|
+
* found in the LICENSE file at https://angular.dev/license
|
|
7
|
+
*/
|
|
8
|
+
import { Signal, ValueEqualityFn } from './api';
|
|
9
|
+
/**
|
|
10
|
+
* Options passed to the `computed` creation function.
|
|
11
|
+
*/
|
|
12
|
+
export interface CreateComputedOptions<T> {
|
|
13
|
+
/**
|
|
14
|
+
* A comparison function which defines equality for computed values.
|
|
15
|
+
*/
|
|
16
|
+
equal?: ValueEqualityFn<T>;
|
|
17
|
+
/**
|
|
18
|
+
* A debug name for the computed signal. Used in Angular DevTools to identify the signal.
|
|
19
|
+
*/
|
|
20
|
+
debugName?: string;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Create a computed `Signal` which derives a reactive value from an expression.
|
|
24
|
+
*/
|
|
25
|
+
export declare function computed<T>(computation: () => T, options?: CreateComputedOptions<T>): Signal<T>;
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright Google LLC All Rights Reserved.
|
|
4
|
+
*
|
|
5
|
+
* Use of this source code is governed by an MIT-style license that can be
|
|
6
|
+
* found in the LICENSE file at https://angular.dev/license
|
|
7
|
+
*/
|
|
8
|
+
import { ReactiveNode, SIGNAL } from '@angular/core/primitives/signals';
|
|
9
|
+
import { InjectionToken } from '../../di/injection_token';
|
|
10
|
+
import { Injector } from '../../di/injector';
|
|
11
|
+
import { ChangeDetectionScheduler } from '../../change_detection/scheduling/zoneless_scheduling';
|
|
12
|
+
import { EffectScheduler, SchedulableEffect } from './root_effect_scheduler';
|
|
13
|
+
/**
|
|
14
|
+
* Toggle the flag on whether to use microtask effects (for testing).
|
|
15
|
+
*/
|
|
16
|
+
export declare function setUseMicrotaskEffectsByDefault(value: boolean): boolean;
|
|
17
|
+
/**
|
|
18
|
+
* A global reactive effect, which can be manually destroyed.
|
|
19
|
+
*
|
|
20
|
+
* @developerPreview
|
|
21
|
+
*/
|
|
22
|
+
export interface EffectRef {
|
|
23
|
+
/**
|
|
24
|
+
* Shut down the effect, removing it from any upcoming scheduled executions.
|
|
25
|
+
*/
|
|
26
|
+
destroy(): void;
|
|
27
|
+
}
|
|
28
|
+
export declare class EffectRefImpl implements EffectRef {
|
|
29
|
+
[SIGNAL]: EffectNode;
|
|
30
|
+
constructor(node: EffectNode);
|
|
31
|
+
destroy(): void;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Options passed to the `effect` function.
|
|
35
|
+
*
|
|
36
|
+
* @developerPreview
|
|
37
|
+
*/
|
|
38
|
+
export interface CreateEffectOptions {
|
|
39
|
+
/**
|
|
40
|
+
* The `Injector` in which to create the effect.
|
|
41
|
+
*
|
|
42
|
+
* If this is not provided, the current [injection context](guide/di/dependency-injection-context)
|
|
43
|
+
* will be used instead (via `inject`).
|
|
44
|
+
*/
|
|
45
|
+
injector?: Injector;
|
|
46
|
+
/**
|
|
47
|
+
* Whether the `effect` should require manual cleanup.
|
|
48
|
+
*
|
|
49
|
+
* If this is `false` (the default) the effect will automatically register itself to be cleaned up
|
|
50
|
+
* with the current `DestroyRef`.
|
|
51
|
+
*/
|
|
52
|
+
manualCleanup?: boolean;
|
|
53
|
+
/**
|
|
54
|
+
* Always create a root effect (which is scheduled as a microtask) regardless of whether `effect`
|
|
55
|
+
* is called within a component.
|
|
56
|
+
*/
|
|
57
|
+
forceRoot?: true;
|
|
58
|
+
/**
|
|
59
|
+
* @deprecated no longer required, signal writes are allowed by default.
|
|
60
|
+
*/
|
|
61
|
+
allowSignalWrites?: boolean;
|
|
62
|
+
/**
|
|
63
|
+
* A debug name for the effect. Used in Angular DevTools to identify the effect.
|
|
64
|
+
*/
|
|
65
|
+
debugName?: string;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* An effect can, optionally, register a cleanup function. If registered, the cleanup is executed
|
|
69
|
+
* before the next effect run. The cleanup function makes it possible to "cancel" any work that the
|
|
70
|
+
* previous effect run might have started.
|
|
71
|
+
*
|
|
72
|
+
* @developerPreview
|
|
73
|
+
*/
|
|
74
|
+
export type EffectCleanupFn = () => void;
|
|
75
|
+
/**
|
|
76
|
+
* A callback passed to the effect function that makes it possible to register cleanup logic.
|
|
77
|
+
*
|
|
78
|
+
* @developerPreview
|
|
79
|
+
*/
|
|
80
|
+
export type EffectCleanupRegisterFn = (cleanupFn: EffectCleanupFn) => void;
|
|
81
|
+
/**
|
|
82
|
+
* Registers an "effect" that will be scheduled & executed whenever the signals that it reads
|
|
83
|
+
* changes.
|
|
84
|
+
*
|
|
85
|
+
* Angular has two different kinds of effect: component effects and root effects. Component effects
|
|
86
|
+
* are created when `effect()` is called from a component, directive, or within a service of a
|
|
87
|
+
* component/directive. Root effects are created when `effect()` is called from outside the
|
|
88
|
+
* component tree, such as in a root service, or when the `forceRoot` option is provided.
|
|
89
|
+
*
|
|
90
|
+
* The two effect types differ in their timing. Component effects run as a component lifecycle
|
|
91
|
+
* event during Angular's synchronization (change detection) process, and can safely read input
|
|
92
|
+
* signals or create/destroy views that depend on component state. Root effects run as microtasks
|
|
93
|
+
* and have no connection to the component tree or change detection.
|
|
94
|
+
*
|
|
95
|
+
* `effect()` must be run in injection context, unless the `injector` option is manually specified.
|
|
96
|
+
*
|
|
97
|
+
* @developerPreview
|
|
98
|
+
*/
|
|
99
|
+
export declare function effect(effectFn: (onCleanup: EffectCleanupRegisterFn) => void, options?: CreateEffectOptions): EffectRef;
|
|
100
|
+
export interface EffectNode extends ReactiveNode, SchedulableEffect {
|
|
101
|
+
hasRun: boolean;
|
|
102
|
+
cleanupFns: EffectCleanupFn[] | undefined;
|
|
103
|
+
injector: Injector;
|
|
104
|
+
notifier: ChangeDetectionScheduler;
|
|
105
|
+
onDestroyFn: () => void;
|
|
106
|
+
fn: (cleanupFn: EffectCleanupRegisterFn) => void;
|
|
107
|
+
run(): void;
|
|
108
|
+
destroy(): void;
|
|
109
|
+
maybeCleanup(): void;
|
|
110
|
+
}
|
|
111
|
+
export interface RootEffectNode extends EffectNode {
|
|
112
|
+
scheduler: EffectScheduler;
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Not public API, which guarantees `EffectScheduler` only ever comes from the application root
|
|
116
|
+
* injector.
|
|
117
|
+
*/
|
|
118
|
+
export declare const APP_EFFECT_SCHEDULER: InjectionToken<EffectScheduler>;
|
|
119
|
+
export declare const BASE_EFFECT_NODE: Omit<EffectNode, 'fn' | 'destroy' | 'injector' | 'notifier'>;
|
|
120
|
+
export declare const ROOT_EFFECT_NODE: Omit<RootEffectNode, 'fn' | 'scheduler' | 'notifier' | 'injector'>;
|
|
121
|
+
export declare function createRootEffect(fn: (onCleanup: EffectCleanupRegisterFn) => void, scheduler: EffectScheduler, notifier: ChangeDetectionScheduler): RootEffectNode;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright Google LLC All Rights Reserved.
|
|
4
|
+
*
|
|
5
|
+
* Use of this source code is governed by an MIT-style license that can be
|
|
6
|
+
* found in the LICENSE file at https://angular.dev/license
|
|
7
|
+
*/
|
|
8
|
+
import { WritableSignal } from './signal';
|
|
9
|
+
import { ValueEqualityFn } from './api';
|
|
10
|
+
/**
|
|
11
|
+
* Creates a writable signal whose value is initialized and reset by the linked, reactive computation.
|
|
12
|
+
*
|
|
13
|
+
* @developerPreview
|
|
14
|
+
*/
|
|
15
|
+
export declare function linkedSignal<D>(computation: () => D, options?: {
|
|
16
|
+
equal?: ValueEqualityFn<NoInfer<D>>;
|
|
17
|
+
}): WritableSignal<D>;
|
|
18
|
+
/**
|
|
19
|
+
* Creates a writable signal whose value is initialized and reset by the linked, reactive computation.
|
|
20
|
+
* This is an advanced API form where the computation has access to the previous value of the signal and the computation result.
|
|
21
|
+
*
|
|
22
|
+
* Note: The computation is reactive, meaning the linked signal will automatically update whenever any of the signals used within the computation change.
|
|
23
|
+
*
|
|
24
|
+
* @developerPreview
|
|
25
|
+
*/
|
|
26
|
+
export declare function linkedSignal<S, D>(options: {
|
|
27
|
+
source: () => S;
|
|
28
|
+
computation: (source: NoInfer<S>, previous?: {
|
|
29
|
+
source: NoInfer<S>;
|
|
30
|
+
value: NoInfer<D>;
|
|
31
|
+
}) => D;
|
|
32
|
+
equal?: ValueEqualityFn<NoInfer<D>>;
|
|
33
|
+
}): WritableSignal<D>;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright Google LLC All Rights Reserved.
|
|
4
|
+
*
|
|
5
|
+
* Use of this source code is governed by an MIT-style license that can be
|
|
6
|
+
* found in the LICENSE file at https://angular.dev/license
|
|
7
|
+
*/
|
|
8
|
+
import type { CreateEffectOptions, EffectCleanupRegisterFn, EffectRef } from './effect';
|
|
9
|
+
import { type SchedulableEffect, ZoneAwareEffectScheduler } from './root_effect_scheduler';
|
|
10
|
+
export declare class MicrotaskEffectScheduler extends ZoneAwareEffectScheduler {
|
|
11
|
+
private readonly pendingTasks;
|
|
12
|
+
private taskId;
|
|
13
|
+
schedule(effect: SchedulableEffect): void;
|
|
14
|
+
flush(): void;
|
|
15
|
+
/** @nocollapse */
|
|
16
|
+
static ɵprov: unknown;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Create a global `Effect` for the given reactive function.
|
|
20
|
+
*/
|
|
21
|
+
export declare function microtaskEffect(effectFn: (onCleanup: EffectCleanupRegisterFn) => void, options?: CreateEffectOptions): EffectRef;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright Google LLC All Rights Reserved.
|
|
4
|
+
*
|
|
5
|
+
* Use of this source code is governed by an MIT-style license that can be
|
|
6
|
+
* found in the LICENSE file at https://angular.dev/license
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* Controls whether effects use the legacy `microtaskEffect` by default.
|
|
10
|
+
*/
|
|
11
|
+
export declare const USE_MICROTASK_EFFECT_BY_DEFAULT = false;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright Google LLC All Rights Reserved.
|
|
4
|
+
*
|
|
5
|
+
* Use of this source code is governed by an MIT-style license that can be
|
|
6
|
+
* found in the LICENSE file at https://angular.dev/license
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* Abstraction that encompasses any kind of effect that can be scheduled.
|
|
10
|
+
*/
|
|
11
|
+
export interface SchedulableEffect {
|
|
12
|
+
run(): void;
|
|
13
|
+
zone: {
|
|
14
|
+
run<T>(fn: () => T): T;
|
|
15
|
+
} | null;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* A scheduler which manages the execution of effects.
|
|
19
|
+
*/
|
|
20
|
+
export declare abstract class EffectScheduler {
|
|
21
|
+
/**
|
|
22
|
+
* Schedule the given effect to be executed at a later time.
|
|
23
|
+
*
|
|
24
|
+
* It is an error to attempt to execute any effects synchronously during a scheduling operation.
|
|
25
|
+
*/
|
|
26
|
+
abstract schedule(e: SchedulableEffect): void;
|
|
27
|
+
/**
|
|
28
|
+
* Run any scheduled effects.
|
|
29
|
+
*/
|
|
30
|
+
abstract flush(): void;
|
|
31
|
+
/** Remove a scheduled effect */
|
|
32
|
+
abstract remove(e: SchedulableEffect): void;
|
|
33
|
+
/** @nocollapse */
|
|
34
|
+
static ɵprov: unknown;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* A wrapper around `ZoneAwareQueueingScheduler` that schedules flushing via the microtask queue
|
|
38
|
+
* when.
|
|
39
|
+
*/
|
|
40
|
+
export declare class ZoneAwareEffectScheduler implements EffectScheduler {
|
|
41
|
+
private queuedEffectCount;
|
|
42
|
+
private queues;
|
|
43
|
+
schedule(handle: SchedulableEffect): void;
|
|
44
|
+
remove(handle: SchedulableEffect): void;
|
|
45
|
+
private enqueue;
|
|
46
|
+
/**
|
|
47
|
+
* Run all scheduled effects.
|
|
48
|
+
*
|
|
49
|
+
* Execution order of effects within the same zone is guaranteed to be FIFO, but there is no
|
|
50
|
+
* ordering guarantee between effects scheduled in different zones.
|
|
51
|
+
*/
|
|
52
|
+
flush(): void;
|
|
53
|
+
private flushQueue;
|
|
54
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright Google LLC All Rights Reserved.
|
|
4
|
+
*
|
|
5
|
+
* Use of this source code is governed by an MIT-style license that can be
|
|
6
|
+
* found in the LICENSE file at https://angular.dev/license
|
|
7
|
+
*/
|
|
8
|
+
import { SignalGetter } from '@angular/core/primitives/signals';
|
|
9
|
+
import { Signal, ValueEqualityFn } from './api';
|
|
10
|
+
/** Symbol used distinguish `WritableSignal` from other non-writable signals and functions. */
|
|
11
|
+
export declare const ɵWRITABLE_SIGNAL: unique symbol;
|
|
12
|
+
/**
|
|
13
|
+
* A `Signal` with a value that can be mutated via a setter interface.
|
|
14
|
+
*/
|
|
15
|
+
export interface WritableSignal<T> extends Signal<T> {
|
|
16
|
+
[ɵWRITABLE_SIGNAL]: T;
|
|
17
|
+
/**
|
|
18
|
+
* Directly set the signal to a new value, and notify any dependents.
|
|
19
|
+
*/
|
|
20
|
+
set(value: T): void;
|
|
21
|
+
/**
|
|
22
|
+
* Update the value of the signal based on its current value, and
|
|
23
|
+
* notify any dependents.
|
|
24
|
+
*/
|
|
25
|
+
update(updateFn: (value: T) => T): void;
|
|
26
|
+
/**
|
|
27
|
+
* Returns a readonly version of this signal. Readonly signals can be accessed to read their value
|
|
28
|
+
* but can't be changed using set or update methods. The readonly signals do _not_ have
|
|
29
|
+
* any built-in mechanism that would prevent deep-mutation of their value.
|
|
30
|
+
*/
|
|
31
|
+
asReadonly(): Signal<T>;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Utility function used during template type checking to extract the value from a `WritableSignal`.
|
|
35
|
+
* @codeGenApi
|
|
36
|
+
*/
|
|
37
|
+
export declare function ɵunwrapWritableSignal<T>(value: T | {
|
|
38
|
+
[ɵWRITABLE_SIGNAL]: T;
|
|
39
|
+
}): T;
|
|
40
|
+
/**
|
|
41
|
+
* Options passed to the `signal` creation function.
|
|
42
|
+
*/
|
|
43
|
+
export interface CreateSignalOptions<T> {
|
|
44
|
+
/**
|
|
45
|
+
* A comparison function which defines equality for signal values.
|
|
46
|
+
*/
|
|
47
|
+
equal?: ValueEqualityFn<T>;
|
|
48
|
+
/**
|
|
49
|
+
* A debug name for the signal. Used in Angular DevTools to identify the signal.
|
|
50
|
+
*/
|
|
51
|
+
debugName?: string;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Create a `Signal` that can be set or updated directly.
|
|
55
|
+
*/
|
|
56
|
+
export declare function signal<T>(initialValue: T, options?: CreateSignalOptions<T>): WritableSignal<T>;
|
|
57
|
+
export declare function signalAsReadonlyFn<T>(this: SignalGetter<T>): Signal<T>;
|
|
58
|
+
/**
|
|
59
|
+
* Checks if the given `value` is a writeable signal.
|
|
60
|
+
*/
|
|
61
|
+
export declare function isWritableSignal(value: unknown): value is WritableSignal<unknown>;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright Google LLC All Rights Reserved.
|
|
4
|
+
*
|
|
5
|
+
* Use of this source code is governed by an MIT-style license that can be
|
|
6
|
+
* found in the LICENSE file at https://angular.dev/license
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* Execute an arbitrary function in a non-reactive (non-tracking) context. The executed function
|
|
10
|
+
* can, optionally, return a value.
|
|
11
|
+
*/
|
|
12
|
+
export declare function untracked<T>(nonReactiveReadsFn: () => T): T;
|