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
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "static-injector",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "6.0.0",
|
|
4
4
|
"description": "Angular 依赖注入独立版本;Angular dependency injection standalone version",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"angular",
|
|
7
|
-
"angular
|
|
7
|
+
"angular 19.0.0",
|
|
8
8
|
"injector",
|
|
9
9
|
"typescript",
|
|
10
10
|
"injectable",
|
|
@@ -16,7 +16,13 @@
|
|
|
16
16
|
"inversion of control container",
|
|
17
17
|
"ioc",
|
|
18
18
|
"javascript",
|
|
19
|
-
"node"
|
|
19
|
+
"node",
|
|
20
|
+
"signal",
|
|
21
|
+
"reactivity",
|
|
22
|
+
"effect",
|
|
23
|
+
"computed",
|
|
24
|
+
"resource",
|
|
25
|
+
"linkedSignal"
|
|
20
26
|
],
|
|
21
27
|
"repository": {
|
|
22
28
|
"type": "git",
|
|
@@ -26,12 +32,15 @@
|
|
|
26
32
|
"url": "https://github.com/wszgrcy/static-injector/issues"
|
|
27
33
|
},
|
|
28
34
|
"homepage": "https://github.com/wszgrcy/static-injector#readme",
|
|
29
|
-
"main": "
|
|
30
|
-
"
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
+
"main": "index.js",
|
|
36
|
+
"exports": {
|
|
37
|
+
".": {
|
|
38
|
+
"import": "./index.mjs",
|
|
39
|
+
"require": "./index.js",
|
|
40
|
+
"default": "./index.mjs",
|
|
41
|
+
"types": "./import/index.d.ts"
|
|
42
|
+
}
|
|
43
|
+
},
|
|
35
44
|
"private": false,
|
|
36
45
|
"scripts": {},
|
|
37
46
|
"author": "wszgrcy",
|
|
@@ -39,4 +48,4 @@
|
|
|
39
48
|
"peerDependencies": {},
|
|
40
49
|
"devDependencies": {},
|
|
41
50
|
"sideEffects": false
|
|
42
|
-
}
|
|
51
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
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
|
+
export { ComputedNode, createComputed } from './src/computed';
|
|
9
|
+
export { ComputationFn, LinkedSignalNode, LinkedSignalGetter, createLinkedSignal, linkedSignalSetFn, linkedSignalUpdateFn, } from './src/linked_signal';
|
|
10
|
+
export { ValueEqualityFn, defaultEquals } from './src/equality';
|
|
11
|
+
export { setThrowInvalidWriteToSignalError } from './src/errors';
|
|
12
|
+
export { REACTIVE_NODE, Reactive, ReactiveNode, SIGNAL, consumerAfterComputation, consumerBeforeComputation, consumerDestroy, consumerMarkDirty, consumerPollProducersForChange, getActiveConsumer, isInNotificationPhase, isReactive, producerAccessed, producerIncrementEpoch, producerMarkClean, producerNotifyConsumers, producerUpdateValueVersion, producerUpdatesAllowed, setActiveConsumer, } from './src/graph';
|
|
13
|
+
export { SIGNAL_NODE, SignalGetter, SignalNode, createSignal, runPostSignalSetFn, setPostSignalSetFn, signalSetFn, signalUpdateFn, } from './src/signal';
|
|
14
|
+
export { Watch, WatchCleanupFn, WatchCleanupRegisterFn, createWatch, } from './src/watch';
|
|
15
|
+
export { setAlternateWeakRefImpl } from './src/weak_ref';
|
|
@@ -0,0 +1,55 @@
|
|
|
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 { ValueEqualityFn } from './equality';
|
|
9
|
+
import { ReactiveNode, SIGNAL } from './graph';
|
|
10
|
+
/**
|
|
11
|
+
* A computation, which derives a value from a declarative reactive expression.
|
|
12
|
+
*
|
|
13
|
+
* `Computed`s are both producers and consumers of reactivity.
|
|
14
|
+
*/
|
|
15
|
+
export interface ComputedNode<T> extends ReactiveNode {
|
|
16
|
+
/**
|
|
17
|
+
* Current value of the computation, or one of the sentinel values above (`UNSET`, `COMPUTING`,
|
|
18
|
+
* `ERROR`).
|
|
19
|
+
*/
|
|
20
|
+
value: T;
|
|
21
|
+
/**
|
|
22
|
+
* If `value` is `ERRORED`, the error caught from the last computation attempt which will
|
|
23
|
+
* be re-thrown.
|
|
24
|
+
*/
|
|
25
|
+
error: unknown;
|
|
26
|
+
/**
|
|
27
|
+
* The computation function which will produce a new value.
|
|
28
|
+
*/
|
|
29
|
+
computation: () => T;
|
|
30
|
+
equal: ValueEqualityFn<T>;
|
|
31
|
+
}
|
|
32
|
+
export type ComputedGetter<T> = (() => T) & {
|
|
33
|
+
[SIGNAL]: ComputedNode<T>;
|
|
34
|
+
};
|
|
35
|
+
/**
|
|
36
|
+
* Create a computed signal which derives a reactive value from an expression.
|
|
37
|
+
*/
|
|
38
|
+
export declare function createComputed<T>(computation: () => T): ComputedGetter<T>;
|
|
39
|
+
/**
|
|
40
|
+
* A dedicated symbol used before a computed value has been calculated for the first time.
|
|
41
|
+
* Explicitly typed as `any` so we can use it as signal's value.
|
|
42
|
+
*/
|
|
43
|
+
export declare const UNSET: any;
|
|
44
|
+
/**
|
|
45
|
+
* A dedicated symbol used in place of a computed signal value to indicate that a given computation
|
|
46
|
+
* is in progress. Used to detect cycles in computation chains.
|
|
47
|
+
* Explicitly typed as `any` so we can use it as signal's value.
|
|
48
|
+
*/
|
|
49
|
+
export declare const COMPUTING: any;
|
|
50
|
+
/**
|
|
51
|
+
* A dedicated symbol used in place of a computed signal value to indicate that a given computation
|
|
52
|
+
* failed. The thrown error is cached until the computation gets dirty again.
|
|
53
|
+
* Explicitly typed as `any` so we can use it as signal's value.
|
|
54
|
+
*/
|
|
55
|
+
export declare const ERRORED: any;
|
|
@@ -0,0 +1,15 @@
|
|
|
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
|
+
* A comparison function which can determine if two values are equal.
|
|
10
|
+
*/
|
|
11
|
+
export type ValueEqualityFn<T> = (a: T, b: T) => boolean;
|
|
12
|
+
/**
|
|
13
|
+
* The default equality function used for `signal` and `computed`, which uses referential equality.
|
|
14
|
+
*/
|
|
15
|
+
export declare function defaultEquals<T>(a: T, b: T): boolean;
|
|
@@ -0,0 +1,10 @@
|
|
|
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 { SignalNode } from './signal';
|
|
9
|
+
export declare function throwInvalidWriteToSignalError<T>(node: SignalNode<T>): void;
|
|
10
|
+
export declare function setThrowInvalidWriteToSignalError(fn: <T>(node: SignalNode<T>) => never): void;
|
|
@@ -0,0 +1,182 @@
|
|
|
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
|
+
type Version = number & {
|
|
9
|
+
__brand: 'Version';
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* Symbol used to tell `Signal`s apart from other functions.
|
|
13
|
+
*
|
|
14
|
+
* This can be used to auto-unwrap signals in various cases, or to auto-wrap non-signal values.
|
|
15
|
+
*/
|
|
16
|
+
export declare const SIGNAL: unique symbol;
|
|
17
|
+
export declare function setActiveConsumer(consumer: ReactiveNode | null): ReactiveNode | null;
|
|
18
|
+
export declare function getActiveConsumer(): ReactiveNode | null;
|
|
19
|
+
export declare function isInNotificationPhase(): boolean;
|
|
20
|
+
export interface Reactive {
|
|
21
|
+
[SIGNAL]: ReactiveNode;
|
|
22
|
+
}
|
|
23
|
+
export declare function isReactive(value: unknown): value is Reactive;
|
|
24
|
+
export declare const REACTIVE_NODE: ReactiveNode;
|
|
25
|
+
/**
|
|
26
|
+
* A producer and/or consumer which participates in the reactive graph.
|
|
27
|
+
*
|
|
28
|
+
* Producer `ReactiveNode`s which are accessed when a consumer `ReactiveNode` is the
|
|
29
|
+
* `activeConsumer` are tracked as dependencies of that consumer.
|
|
30
|
+
*
|
|
31
|
+
* Certain consumers are also tracked as "live" consumers and create edges in the other direction,
|
|
32
|
+
* from producer to consumer. These edges are used to propagate change notifications when a
|
|
33
|
+
* producer's value is updated.
|
|
34
|
+
*
|
|
35
|
+
* A `ReactiveNode` may be both a producer and consumer.
|
|
36
|
+
*/
|
|
37
|
+
export interface ReactiveNode {
|
|
38
|
+
/**
|
|
39
|
+
* Version of the value that this node produces.
|
|
40
|
+
*
|
|
41
|
+
* This is incremented whenever a new value is produced by this node which is not equal to the
|
|
42
|
+
* previous value (by whatever definition of equality is in use).
|
|
43
|
+
*/
|
|
44
|
+
version: Version;
|
|
45
|
+
/**
|
|
46
|
+
* Epoch at which this node is verified to be clean.
|
|
47
|
+
*
|
|
48
|
+
* This allows skipping of some polling operations in the case where no signals have been set
|
|
49
|
+
* since this node was last read.
|
|
50
|
+
*/
|
|
51
|
+
lastCleanEpoch: Version;
|
|
52
|
+
/**
|
|
53
|
+
* Whether this node (in its consumer capacity) is dirty.
|
|
54
|
+
*
|
|
55
|
+
* Only live consumers become dirty, when receiving a change notification from a dependency
|
|
56
|
+
* producer.
|
|
57
|
+
*/
|
|
58
|
+
dirty: boolean;
|
|
59
|
+
/**
|
|
60
|
+
* Producers which are dependencies of this consumer.
|
|
61
|
+
*
|
|
62
|
+
* Uses the same indices as the `producerLastReadVersion` and `producerIndexOfThis` arrays.
|
|
63
|
+
*/
|
|
64
|
+
producerNode: ReactiveNode[] | undefined;
|
|
65
|
+
/**
|
|
66
|
+
* `Version` of the value last read by a given producer.
|
|
67
|
+
*
|
|
68
|
+
* Uses the same indices as the `producerNode` and `producerIndexOfThis` arrays.
|
|
69
|
+
*/
|
|
70
|
+
producerLastReadVersion: Version[] | undefined;
|
|
71
|
+
/**
|
|
72
|
+
* Index of `this` (consumer) in each producer's `liveConsumers` array.
|
|
73
|
+
*
|
|
74
|
+
* This value is only meaningful if this node is live (`liveConsumers.length > 0`). Otherwise
|
|
75
|
+
* these indices are stale.
|
|
76
|
+
*
|
|
77
|
+
* Uses the same indices as the `producerNode` and `producerLastReadVersion` arrays.
|
|
78
|
+
*/
|
|
79
|
+
producerIndexOfThis: number[] | undefined;
|
|
80
|
+
/**
|
|
81
|
+
* Index into the producer arrays that the next dependency of this node as a consumer will use.
|
|
82
|
+
*
|
|
83
|
+
* This index is zeroed before this node as a consumer begins executing. When a producer is read,
|
|
84
|
+
* it gets inserted into the producers arrays at this index. There may be an existing dependency
|
|
85
|
+
* in this location which may or may not match the incoming producer, depending on whether the
|
|
86
|
+
* same producers were read in the same order as the last computation.
|
|
87
|
+
*/
|
|
88
|
+
nextProducerIndex: number;
|
|
89
|
+
/**
|
|
90
|
+
* Array of consumers of this producer that are "live" (they require push notifications).
|
|
91
|
+
*
|
|
92
|
+
* `liveConsumerNode.length` is effectively our reference count for this node.
|
|
93
|
+
*/
|
|
94
|
+
liveConsumerNode: ReactiveNode[] | undefined;
|
|
95
|
+
/**
|
|
96
|
+
* Index of `this` (producer) in each consumer's `producerNode` array.
|
|
97
|
+
*
|
|
98
|
+
* Uses the same indices as the `liveConsumerNode` array.
|
|
99
|
+
*/
|
|
100
|
+
liveConsumerIndexOfThis: number[] | undefined;
|
|
101
|
+
/**
|
|
102
|
+
* Whether writes to signals are allowed when this consumer is the `activeConsumer`.
|
|
103
|
+
*
|
|
104
|
+
* This is used to enforce guardrails such as preventing writes to writable signals in the
|
|
105
|
+
* computation function of computed signals, which is supposed to be pure.
|
|
106
|
+
*/
|
|
107
|
+
consumerAllowSignalWrites: boolean;
|
|
108
|
+
readonly consumerIsAlwaysLive: boolean;
|
|
109
|
+
/**
|
|
110
|
+
* Tracks whether producers need to recompute their value independently of the reactive graph (for
|
|
111
|
+
* example, if no initial value has been computed).
|
|
112
|
+
*/
|
|
113
|
+
producerMustRecompute(node: unknown): boolean;
|
|
114
|
+
producerRecomputeValue(node: unknown): void;
|
|
115
|
+
consumerMarkedDirty(node: unknown): void;
|
|
116
|
+
/**
|
|
117
|
+
* Called when a signal is read within this consumer.
|
|
118
|
+
*/
|
|
119
|
+
consumerOnSignalRead(node: unknown): void;
|
|
120
|
+
/**
|
|
121
|
+
* A debug name for the reactive node. Used in Angular DevTools to identify the node.
|
|
122
|
+
*/
|
|
123
|
+
debugName?: string;
|
|
124
|
+
/**
|
|
125
|
+
* Kind of node. Example: 'signal', 'computed', 'input', 'effect'.
|
|
126
|
+
*
|
|
127
|
+
* ReactiveNode has this as 'unknown' by default, but derived node types should override this to
|
|
128
|
+
* make available the kind of signal that particular instance of a ReactiveNode represents.
|
|
129
|
+
*
|
|
130
|
+
* Used in Angular DevTools to identify the kind of signal.
|
|
131
|
+
*/
|
|
132
|
+
kind: string;
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Called by implementations when a producer's signal is read.
|
|
136
|
+
*/
|
|
137
|
+
export declare function producerAccessed(node: ReactiveNode): void;
|
|
138
|
+
/**
|
|
139
|
+
* Increment the global epoch counter.
|
|
140
|
+
*
|
|
141
|
+
* Called by source producers (that is, not computeds) whenever their values change.
|
|
142
|
+
*/
|
|
143
|
+
export declare function producerIncrementEpoch(): void;
|
|
144
|
+
/**
|
|
145
|
+
* Ensure this producer's `version` is up-to-date.
|
|
146
|
+
*/
|
|
147
|
+
export declare function producerUpdateValueVersion(node: ReactiveNode): void;
|
|
148
|
+
/**
|
|
149
|
+
* Propagate a dirty notification to live consumers of this producer.
|
|
150
|
+
*/
|
|
151
|
+
export declare function producerNotifyConsumers(node: ReactiveNode): void;
|
|
152
|
+
/**
|
|
153
|
+
* Whether this `ReactiveNode` in its producer capacity is currently allowed to initiate updates,
|
|
154
|
+
* based on the current consumer context.
|
|
155
|
+
*/
|
|
156
|
+
export declare function producerUpdatesAllowed(): boolean;
|
|
157
|
+
export declare function consumerMarkDirty(node: ReactiveNode): void;
|
|
158
|
+
export declare function producerMarkClean(node: ReactiveNode): void;
|
|
159
|
+
/**
|
|
160
|
+
* Prepare this consumer to run a computation in its reactive context.
|
|
161
|
+
*
|
|
162
|
+
* Must be called by subclasses which represent reactive computations, before those computations
|
|
163
|
+
* begin.
|
|
164
|
+
*/
|
|
165
|
+
export declare function consumerBeforeComputation(node: ReactiveNode | null): ReactiveNode | null;
|
|
166
|
+
/**
|
|
167
|
+
* Finalize this consumer's state after a reactive computation has run.
|
|
168
|
+
*
|
|
169
|
+
* Must be called by subclasses which represent reactive computations, after those computations
|
|
170
|
+
* have finished.
|
|
171
|
+
*/
|
|
172
|
+
export declare function consumerAfterComputation(node: ReactiveNode | null, prevConsumer: ReactiveNode | null): void;
|
|
173
|
+
/**
|
|
174
|
+
* Determine whether this consumer has any dependencies which have changed since the last time
|
|
175
|
+
* they were read.
|
|
176
|
+
*/
|
|
177
|
+
export declare function consumerPollProducersForChange(node: ReactiveNode): boolean;
|
|
178
|
+
/**
|
|
179
|
+
* Disconnect this consumer from the graph.
|
|
180
|
+
*/
|
|
181
|
+
export declare function consumerDestroy(node: ReactiveNode): void;
|
|
182
|
+
export {};
|
|
@@ -0,0 +1,72 @@
|
|
|
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 { defaultEquals, ValueEqualityFn } from './equality';
|
|
9
|
+
import { ReactiveNode, SIGNAL } from './graph';
|
|
10
|
+
export type ComputationFn<S, D> = (source: S, previous?: {
|
|
11
|
+
source: S;
|
|
12
|
+
value: D;
|
|
13
|
+
}) => D;
|
|
14
|
+
export interface LinkedSignalNode<S, D> extends ReactiveNode {
|
|
15
|
+
/**
|
|
16
|
+
* Value of the source signal that was used to derive the computed value.
|
|
17
|
+
*/
|
|
18
|
+
sourceValue: S;
|
|
19
|
+
/**
|
|
20
|
+
* Current state value, or one of the sentinel values (`UNSET`, `COMPUTING`,
|
|
21
|
+
* `ERROR`).
|
|
22
|
+
*/
|
|
23
|
+
value: D;
|
|
24
|
+
/**
|
|
25
|
+
* If `value` is `ERRORED`, the error caught from the last computation attempt which will
|
|
26
|
+
* be re-thrown.
|
|
27
|
+
*/
|
|
28
|
+
error: unknown;
|
|
29
|
+
/**
|
|
30
|
+
* The source function represents reactive dependency based on which the linked state is reset.
|
|
31
|
+
*/
|
|
32
|
+
source: () => S;
|
|
33
|
+
/**
|
|
34
|
+
* The computation function which will produce a new value based on the source and, optionally - previous values.
|
|
35
|
+
*/
|
|
36
|
+
computation: ComputationFn<S, D>;
|
|
37
|
+
equal: ValueEqualityFn<D>;
|
|
38
|
+
}
|
|
39
|
+
export type LinkedSignalGetter<S, D> = (() => D) & {
|
|
40
|
+
[SIGNAL]: LinkedSignalNode<S, D>;
|
|
41
|
+
};
|
|
42
|
+
export declare function createLinkedSignal<S, D>(sourceFn: () => S, computationFn: ComputationFn<S, D>, equalityFn?: ValueEqualityFn<D>): LinkedSignalGetter<S, D>;
|
|
43
|
+
export declare function linkedSignalSetFn<S, D>(node: LinkedSignalNode<S, D>, newValue: D): void;
|
|
44
|
+
export declare function linkedSignalUpdateFn<S, D>(node: LinkedSignalNode<S, D>, updater: (value: D) => D): void;
|
|
45
|
+
export declare const LINKED_SIGNAL_NODE: {
|
|
46
|
+
value: any;
|
|
47
|
+
dirty: boolean;
|
|
48
|
+
error: null;
|
|
49
|
+
equal: typeof defaultEquals;
|
|
50
|
+
producerMustRecompute(node: LinkedSignalNode<unknown, unknown>): boolean;
|
|
51
|
+
producerRecomputeValue(node: LinkedSignalNode<unknown, unknown>): void;
|
|
52
|
+
version: number & {
|
|
53
|
+
__brand: "Version";
|
|
54
|
+
};
|
|
55
|
+
lastCleanEpoch: number & {
|
|
56
|
+
__brand: "Version";
|
|
57
|
+
};
|
|
58
|
+
producerNode: ReactiveNode[] | undefined;
|
|
59
|
+
producerLastReadVersion: (number & {
|
|
60
|
+
__brand: "Version";
|
|
61
|
+
})[] | undefined;
|
|
62
|
+
producerIndexOfThis: number[] | undefined;
|
|
63
|
+
nextProducerIndex: number;
|
|
64
|
+
liveConsumerNode: ReactiveNode[] | undefined;
|
|
65
|
+
liveConsumerIndexOfThis: number[] | undefined;
|
|
66
|
+
consumerAllowSignalWrites: boolean;
|
|
67
|
+
consumerIsAlwaysLive: boolean;
|
|
68
|
+
consumerMarkedDirty(node: unknown): void;
|
|
69
|
+
consumerOnSignalRead(node: unknown): void;
|
|
70
|
+
debugName?: string;
|
|
71
|
+
kind: string;
|
|
72
|
+
};
|
|
@@ -0,0 +1,29 @@
|
|
|
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 { ValueEqualityFn } from './equality';
|
|
9
|
+
import { ReactiveNode, SIGNAL } from './graph';
|
|
10
|
+
export interface SignalNode<T> extends ReactiveNode {
|
|
11
|
+
value: T;
|
|
12
|
+
equal: ValueEqualityFn<T>;
|
|
13
|
+
}
|
|
14
|
+
export type SignalBaseGetter<T> = (() => T) & {
|
|
15
|
+
readonly [SIGNAL]: unknown;
|
|
16
|
+
};
|
|
17
|
+
export interface SignalGetter<T> extends SignalBaseGetter<T> {
|
|
18
|
+
readonly [SIGNAL]: SignalNode<T>;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Create a `Signal` that can be set or updated directly.
|
|
22
|
+
*/
|
|
23
|
+
export declare function createSignal<T>(initialValue: T): SignalGetter<T>;
|
|
24
|
+
export declare function setPostSignalSetFn(fn: (() => void) | null): (() => void) | null;
|
|
25
|
+
export declare function signalGetFn<T>(this: SignalNode<T>): T;
|
|
26
|
+
export declare function signalSetFn<T>(node: SignalNode<T>, newValue: T): void;
|
|
27
|
+
export declare function signalUpdateFn<T>(node: SignalNode<T>, updater: (value: T) => T): void;
|
|
28
|
+
export declare function runPostSignalSetFn(): void;
|
|
29
|
+
export declare const SIGNAL_NODE: SignalNode<unknown>;
|
|
@@ -0,0 +1,43 @@
|
|
|
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 './graph';
|
|
9
|
+
/**
|
|
10
|
+
* A cleanup function that can be optionally registered from the watch logic. If registered, the
|
|
11
|
+
* cleanup logic runs before the next watch execution.
|
|
12
|
+
*/
|
|
13
|
+
export type WatchCleanupFn = () => void;
|
|
14
|
+
/**
|
|
15
|
+
* A callback passed to the watch function that makes it possible to register cleanup logic.
|
|
16
|
+
*/
|
|
17
|
+
export type WatchCleanupRegisterFn = (cleanupFn: WatchCleanupFn) => void;
|
|
18
|
+
export interface Watch {
|
|
19
|
+
notify(): void;
|
|
20
|
+
/**
|
|
21
|
+
* Execute the reactive expression in the context of this `Watch` consumer.
|
|
22
|
+
*
|
|
23
|
+
* Should be called by the user scheduling algorithm when the provided
|
|
24
|
+
* `schedule` hook is called by `Watch`.
|
|
25
|
+
*/
|
|
26
|
+
run(): void;
|
|
27
|
+
cleanup(): void;
|
|
28
|
+
/**
|
|
29
|
+
* Destroy the watcher:
|
|
30
|
+
* - disconnect it from the reactive graph;
|
|
31
|
+
* - mark it as destroyed so subsequent run and notify operations are noop.
|
|
32
|
+
*/
|
|
33
|
+
destroy(): void;
|
|
34
|
+
[SIGNAL]: WatchNode;
|
|
35
|
+
}
|
|
36
|
+
export interface WatchNode extends ReactiveNode {
|
|
37
|
+
hasRun: boolean;
|
|
38
|
+
fn: ((onCleanup: WatchCleanupRegisterFn) => void) | null;
|
|
39
|
+
schedule: ((watch: Watch) => void) | null;
|
|
40
|
+
cleanupFn: WatchCleanupFn;
|
|
41
|
+
ref: Watch;
|
|
42
|
+
}
|
|
43
|
+
export declare function createWatch(fn: (onCleanup: WatchCleanupRegisterFn) => void, schedule: (watch: Watch) => void, allowSignalWrites: boolean): Watch;
|
|
@@ -3,6 +3,6 @@
|
|
|
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
|
-
export
|
|
8
|
+
export declare function setAlternateWeakRefImpl(impl: unknown): void;
|
package/readme.md
CHANGED
|
@@ -8,9 +8,7 @@
|
|
|
8
8
|
- No transformer required
|
|
9
9
|
- 0 dependencies
|
|
10
10
|
- Remove Decorator
|
|
11
|
-
> `@Injectable()`=>`static injectOptions={}`
|
|
12
|
-
> `@Inject() xx`=>`xx=inject()`
|
|
13
|
-
> `@Optional()`=>`xx=inject(token,{optional:true})`
|
|
11
|
+
> `@Injectable()`=>`static injectOptions={}` > `@Inject() xx`=>`xx=inject()` > `@Optional()`=>`xx=inject(token,{optional:true})`
|
|
14
12
|
- `JS`/`TS` Support
|
|
15
13
|
|
|
16
14
|
# Source
|
|
@@ -20,8 +18,16 @@
|
|
|
20
18
|
# Usage
|
|
21
19
|
|
|
22
20
|
- Create a first level dependency injector with `Injector.create`
|
|
21
|
+
|
|
23
22
|
```ts
|
|
24
|
-
import {
|
|
23
|
+
import {
|
|
24
|
+
Injector,
|
|
25
|
+
inject,
|
|
26
|
+
// root
|
|
27
|
+
createRootInjector,
|
|
28
|
+
// child
|
|
29
|
+
createInjector,
|
|
30
|
+
} from 'static-injector';
|
|
25
31
|
|
|
26
32
|
class Main {
|
|
27
33
|
child = inject(Child);
|
|
@@ -31,23 +37,20 @@ class Child {
|
|
|
31
37
|
return 'hello world';
|
|
32
38
|
}
|
|
33
39
|
}
|
|
34
|
-
let injector =
|
|
40
|
+
let injector = createRootInjector({ providers: [Main, Child] });
|
|
35
41
|
const instance = injector.get(Main);
|
|
36
42
|
console.log(instance.child.output());
|
|
37
43
|
```
|
|
38
44
|
|
|
39
|
-
# Different from `injection-js`
|
|
40
|
-
|
|
41
|
-
- `injection-js` belongs to dynamic dependency injection and is a version used before Angular5. Currently no longer updated
|
|
42
|
-
- The two are basically interchangeable (the details need to be adjusted)
|
|
43
|
-
|
|
44
|
-
- Support the use of `inject` during construction
|
|
45
|
-
|
|
46
45
|
# No Decorator
|
|
47
46
|
|
|
48
47
|
- The original use of `@Injectable()` to pass parameters has been changed to `static injectOptions={}`. If there are no parameters, there is no need to set them
|
|
49
48
|
- Originally, `@Optional`, `@SkipSelf`, `@Self`, please use the second pass parameter of `inject` instead
|
|
50
49
|
|
|
50
|
+
# reactivity
|
|
51
|
+
|
|
52
|
+
- support `signal`,`effect`,`resource`,`linkedSignal`,`computed`
|
|
53
|
+
|
|
51
54
|
# Test
|
|
52
55
|
|
|
53
56
|
- Partially conducted unit testing to ensure that most functions are functioning properly
|
|
@@ -58,4 +61,5 @@ console.log(instance.child.output());
|
|
|
58
61
|
- Currently, the synchronization logic has been refactored and modified using `@code-recycle/cli` to ensure consistency with the official version of `angular`
|
|
59
62
|
|
|
60
63
|
# Examples
|
|
61
|
-
|
|
64
|
+
|
|
65
|
+
- [https://github.com/wszgrcy/static-injector/tree/main/test/import](https://github.com/wszgrcy/static-injector/tree/main/test/import)
|