static-injector 5.0.1 → 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.
Files changed (110) hide show
  1. package/import/change_detection/scheduling/zoneless_scheduling.d.ts +37 -0
  2. package/import/change_detection/scheduling/zoneless_scheduling_impl.d.ts +16 -0
  3. package/import/core_reactivity_export_internal.d.ts +17 -0
  4. package/import/di/contextual.d.ts +36 -0
  5. package/{typings → import}/di/create_injector.d.ts +1 -1
  6. package/{typings → import}/di/forward_ref.d.ts +2 -2
  7. package/import/di/index.d.ts +3 -0
  8. package/{typings → import}/di/initializer_token.d.ts +8 -1
  9. package/{typings → import}/di/inject_switch.d.ts +2 -2
  10. package/{typings → import}/di/injectable.d.ts +4 -4
  11. package/{typings → import}/di/injection_token.d.ts +3 -4
  12. package/{typings → import}/di/injector.d.ts +4 -4
  13. package/{typings → import}/di/injector_compatibility.d.ts +1 -1
  14. package/{typings → import}/di/injector_marker.d.ts +1 -1
  15. package/{typings → import}/di/injector_token.d.ts +1 -1
  16. package/{typings → import}/di/interface/defs.d.ts +1 -1
  17. package/{typings → import}/di/interface/injector.d.ts +1 -1
  18. package/{typings → import}/di/interface/provider.d.ts +16 -18
  19. package/{typings → import}/di/internal_tokens.d.ts +1 -1
  20. package/{typings → import}/di/metadata.d.ts +9 -13
  21. package/{typings → import}/di/null_injector.d.ts +1 -1
  22. package/{typings → import}/di/provider_collection.d.ts +32 -4
  23. package/{typings → import}/di/provider_token.d.ts +1 -1
  24. package/{typings → import}/di/r3_injector.d.ts +2 -2
  25. package/{typings → import}/di/scope.d.ts +1 -1
  26. package/{typings → import}/di.d.ts +1 -1
  27. package/import/error_handler.d.ts +45 -0
  28. package/{typings → import}/errors.d.ts +13 -7
  29. package/import/index.d.ts +37 -0
  30. package/{typings → import}/interface/lifecycle_hooks.d.ts +2 -2
  31. package/{typings → import}/interface/type.d.ts +4 -9
  32. package/import/linker/destroy_ref.d.ts +44 -0
  33. package/import/pending_tasks.d.ts +78 -0
  34. package/{typings → import}/render3/definition_factory.d.ts +1 -1
  35. package/{typings → import}/render3/errors_di.d.ts +1 -1
  36. package/{typings → import}/render3/fields.d.ts +1 -1
  37. package/{typings → import}/render3/instructions/di.d.ts +1 -1
  38. package/import/render3/reactivity/api.d.ts +27 -0
  39. package/import/render3/reactivity/asserts.d.ts +16 -0
  40. package/import/render3/reactivity/computed.d.ts +25 -0
  41. package/import/render3/reactivity/effect.d.ts +121 -0
  42. package/import/render3/reactivity/linked_signal.d.ts +33 -0
  43. package/import/render3/reactivity/microtask_effect.d.ts +21 -0
  44. package/import/render3/reactivity/patch.d.ts +11 -0
  45. package/import/render3/reactivity/root_effect_scheduler.d.ts +54 -0
  46. package/import/render3/reactivity/signal.d.ts +61 -0
  47. package/import/render3/reactivity/untracked.d.ts +12 -0
  48. package/import/resource/api.d.ts +219 -0
  49. package/{es2022/di/injectable.js → import/resource/index.d.ts} +3 -2
  50. package/import/resource/resource.d.ts +89 -0
  51. package/import/util/callback_scheduler.d.ts +35 -0
  52. package/{typings → import}/util/closure.d.ts +1 -1
  53. package/{typings → import}/util/decorators.d.ts +3 -3
  54. package/{typings → import}/util/empty.d.ts +1 -1
  55. package/{es2022/di/provider_token.js → import/util/noop.d.ts} +2 -2
  56. package/{typings → import}/util/property.d.ts +1 -1
  57. package/{typings → import}/util/stringify.d.ts +1 -1
  58. package/index.js +2349 -0
  59. package/index.js.map +7 -0
  60. package/index.mjs +2258 -0
  61. package/index.mjs.map +7 -0
  62. package/package.json +19 -10
  63. package/primitives/signals/index.d.ts +15 -0
  64. package/primitives/signals/src/computed.d.ts +55 -0
  65. package/primitives/signals/src/equality.d.ts +15 -0
  66. package/primitives/signals/src/errors.d.ts +10 -0
  67. package/primitives/signals/src/graph.d.ts +182 -0
  68. package/primitives/signals/src/linked_signal.d.ts +72 -0
  69. package/primitives/signals/src/signal.d.ts +29 -0
  70. package/primitives/signals/src/watch.d.ts +43 -0
  71. package/{es2022/di/injector_marker.js → primitives/signals/src/weak_ref.d.ts} +2 -2
  72. package/readme.md +18 -14
  73. package/commonjs/index.js +0 -1576
  74. package/es2022/di/create_injector.js +0 -32
  75. package/es2022/di/forward_ref.js +0 -80
  76. package/es2022/di/index.js +0 -1
  77. package/es2022/di/initializer_token.js +0 -15
  78. package/es2022/di/inject_switch.js +0 -51
  79. package/es2022/di/injection_token.js +0 -93
  80. package/es2022/di/injector.js +0 -60
  81. package/es2022/di/injector_compatibility.js +0 -265
  82. package/es2022/di/injector_token.js +0 -20
  83. package/es2022/di/interface/defs.js +0 -110
  84. package/es2022/di/interface/injector.js +0 -26
  85. package/es2022/di/interface/provider.js +0 -10
  86. package/es2022/di/internal_tokens.js +0 -9
  87. package/es2022/di/metadata.js +0 -49
  88. package/es2022/di/null_injector.js +0 -19
  89. package/es2022/di/provider_collection.js +0 -104
  90. package/es2022/di/r3_injector.js +0 -449
  91. package/es2022/di/scope.js +0 -14
  92. package/es2022/di.js +0 -24
  93. package/es2022/errors.js +0 -44
  94. package/es2022/index.js +0 -11
  95. package/es2022/interface/lifecycle_hooks.js +0 -8
  96. package/es2022/interface/type.js +0 -21
  97. package/es2022/render3/definition_factory.js +0 -10
  98. package/es2022/render3/errors_di.js +0 -13
  99. package/es2022/render3/fields.js +0 -22
  100. package/es2022/render3/instructions/di.js +0 -23
  101. package/es2022/render3/util/stringify_utils.js +0 -38
  102. package/es2022/util/closure.js +0 -19
  103. package/es2022/util/decorators.js +0 -31
  104. package/es2022/util/empty.js +0 -18
  105. package/es2022/util/property.js +0 -15
  106. package/es2022/util/stringify.js +0 -45
  107. package/fesm2022/index.js +0 -1539
  108. package/typings/di/index.d.ts +0 -1
  109. package/typings/index.d.ts +0 -11
  110. package/typings/render3/util/stringify_utils.d.ts +0 -21
@@ -0,0 +1,45 @@
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
+ * Provides a hook for centralized exception handling.
10
+ *
11
+ * The default implementation of `ErrorHandler` prints error messages to the `console`. To
12
+ * intercept error handling, write a custom exception handler that replaces this default as
13
+ * appropriate for your app.
14
+ *
15
+ * @usageNotes
16
+ * ### Example
17
+ *
18
+ * ```ts
19
+ * class MyErrorHandler implements ErrorHandler {
20
+ * handleError(error) {
21
+ * // do something with the exception
22
+ * }
23
+ * }
24
+ *
25
+ * // Provide in standalone apps
26
+ * bootstrapApplication(AppComponent, {
27
+ * providers: [{provide: ErrorHandler, useClass: MyErrorHandler}]
28
+ * })
29
+ *
30
+ * // Provide in module-based apps
31
+ * @NgModule({
32
+ * providers: [{provide: ErrorHandler, useClass: MyErrorHandler}]
33
+ * })
34
+ * class MyModule {}
35
+ * ```
36
+ *
37
+ * @publicApi
38
+ */
39
+ export declare class ErrorHandler {
40
+ /**
41
+ * @internal
42
+ */
43
+ _console: Console;
44
+ handleError(error: any): void;
45
+ }
@@ -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.io/license
6
+ * found in the LICENSE file at https://angular.dev/license
7
7
  */
8
8
  /**
9
9
  * The list of error codes used in runtime code of the `core` package.
@@ -13,7 +13,7 @@
13
13
  * angular.io. This extra annotation is needed to avoid introducing a separate set to store
14
14
  * error codes which have guides, which might leak into runtime code.
15
15
  *
16
- * Full list of available error guides can be found at https://angular.io/errors.
16
+ * Full list of available error guides can be found at https://angular.dev/errors.
17
17
  *
18
18
  * Error code ranges per package:
19
19
  * - core (this package): 100-999
@@ -51,6 +51,7 @@ export declare const enum RuntimeErrorCode {
51
51
  HOST_DIRECTIVE_UNDEFINED_BINDING = 311,
52
52
  HOST_DIRECTIVE_CONFLICTING_ALIAS = 312,
53
53
  MULTIPLE_MATCHING_PIPES = 313,
54
+ UNINITIALIZED_LET_ACCESS = 314,
54
55
  MULTIPLE_PLATFORMS = 400,
55
56
  PLATFORM_NOT_FOUND = 401,
56
57
  MISSING_REQUIRED_INJECTABLE_IN_BOOTSTRAP = 402,
@@ -59,6 +60,7 @@ export declare const enum RuntimeErrorCode {
59
60
  ASYNC_INITIALIZERS_STILL_RUNNING = 405,
60
61
  APPLICATION_REF_ALREADY_DESTROYED = 406,
61
62
  RENDERER_NOT_FOUND = 407,
63
+ PROVIDED_BOTH_ZONE_AND_ZONELESS = 408,
62
64
  HYDRATION_NODE_MISMATCH = -500,
63
65
  HYDRATION_MISSING_SIBLINGS = -501,
64
66
  HYDRATION_MISSING_NODE = -502,
@@ -67,12 +69,13 @@ export declare const enum RuntimeErrorCode {
67
69
  MISSING_HYDRATION_ANNOTATIONS = -505,
68
70
  HYDRATION_STABLE_TIMEDOUT = -506,
69
71
  MISSING_SSR_CONTENT_INTEGRITY_MARKER = -507,
72
+ MISCONFIGURED_INCREMENTAL_HYDRATION = 508,
70
73
  SIGNAL_WRITE_FROM_ILLEGAL_CONTEXT = 600,
71
74
  REQUIRE_SYNC_WITHOUT_SYNC_EMIT = 601,
72
75
  ASSERTION_NOT_INSIDE_REACTIVE_CONTEXT = -602,
73
76
  INVALID_I18N_STRUCTURE = 700,
74
77
  MISSING_LOCALE_DATA = 701,
75
- DEFER_LOADING_FAILED = 750,
78
+ DEFER_LOADING_FAILED = -750,
76
79
  IMPORT_PROVIDERS_FROM_STANDALONE = 800,
77
80
  INVALID_DIFFER_INPUT = 900,
78
81
  NO_SUPPORTING_DIFFER_FACTORY = 901,
@@ -88,19 +91,22 @@ export declare const enum RuntimeErrorCode {
88
91
  VIEW_ALREADY_DESTROYED = 911,
89
92
  COMPONENT_ID_COLLISION = -912,
90
93
  IMAGE_PERFORMANCE_WARNING = -913,
94
+ UNEXPECTED_ZONEJS_PRESENT_IN_ZONELESS_MODE = 914,
91
95
  REQUIRED_INPUT_NO_VALUE = -950,
92
96
  REQUIRED_QUERY_NO_VALUE = -951,
93
- REQUIRED_MODEL_NO_VALUE = -952,
97
+ REQUIRED_MODEL_NO_VALUE = 952,
94
98
  OUTPUT_REF_DESTROYED = 953,
95
- RUNTIME_DEPS_INVALID_IMPORTED_TYPE = 1000,
96
- RUNTIME_DEPS_ORPHAN_COMPONENT = 1001
99
+ LOOP_TRACK_DUPLICATE_KEYS = -955,
100
+ LOOP_TRACK_RECREATE = -956,
101
+ RUNTIME_DEPS_INVALID_IMPORTED_TYPE = 980,
102
+ RUNTIME_DEPS_ORPHAN_COMPONENT = 981
97
103
  }
98
104
  /**
99
105
  * Class that represents a runtime error.
100
106
  * Formats and outputs the error message in a consistent way.
101
107
  *
102
108
  * Example:
103
- * ```
109
+ * ```ts
104
110
  * throw new RuntimeError(
105
111
  * RuntimeErrorCode.INJECTOR_ALREADY_DESTROYED,
106
112
  * ngDevMode && 'Injector has already been destroyed.');
@@ -0,0 +1,37 @@
1
+ import type { InjectableDecorator } from './di/injectable';
2
+ import { Injector } from './di/injector';
3
+ import { EnvironmentProviders, Provider } from './di/interface/provider';
4
+ import { R3Injector } from './di/r3_injector';
5
+ import { InjectorScope } from './di/scope';
6
+ export * from './di/injectable';
7
+ export * from './di/metadata';
8
+ export * from './di/r3_injector';
9
+ export * from './di/interface/defs';
10
+ export * from './di/injector_compatibility';
11
+ export * from './di/injection_token';
12
+ export * from './di/null_injector';
13
+ export * from './di/injector';
14
+ export * from './di/interface/injector';
15
+ export * from './di/scope';
16
+ export * from './render3/instructions/di';
17
+ export * from './core_reactivity_export_internal';
18
+ export * from './change_detection/scheduling/zoneless_scheduling';
19
+ export * from './change_detection/scheduling/zoneless_scheduling_impl';
20
+ export * from './resource';
21
+ export declare class StaticInjectOptions {
22
+ static injectOptions: Parameters<InjectableDecorator>[0];
23
+ }
24
+ export declare class RootStaticInjectOptions {
25
+ static injectOptions: Parameters<InjectableDecorator>[0];
26
+ }
27
+ export declare function createInjector(options: {
28
+ providers: Array<Provider | EnvironmentProviders>;
29
+ parent: Injector;
30
+ name?: string;
31
+ scopes?: Set<InjectorScope>;
32
+ }): R3Injector;
33
+ export declare function createRootInjector(options: {
34
+ providers: Array<Provider | EnvironmentProviders>;
35
+ name?: string;
36
+ scopes?: Set<InjectorScope>;
37
+ }): R3Injector;
@@ -3,13 +3,13 @@
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.io/license
6
+ * found in the LICENSE file at https://angular.dev/license
7
7
  */
8
8
  /**
9
9
  * A lifecycle hook that is called when a directive, pipe, or service is destroyed.
10
10
  * Use for any custom cleanup that needs to occur when the
11
11
  * instance is destroyed.
12
- * @see [Lifecycle hooks guide](guide/lifecycle-hooks)
12
+ * @see [Lifecycle hooks guide](guide/components/lifecycle)
13
13
  *
14
14
  * @usageNotes
15
15
  * The following snippet shows how a component can implement this interface
@@ -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.io/license
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.io/license
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.io/license
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.io/license
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.io/license
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;