@adaas/a-utils 0.1.31 → 0.1.33

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adaas/a-utils",
3
- "version": "0.1.31",
3
+ "version": "0.1.33",
4
4
  "description": "A-Utils is a set of utilities that are used across the ADAAS ecosystem. This package is designed to be a collection of utilities that are used across the ADAAS ecosystem.",
5
5
  "license": "Apache-2.0",
6
6
  "main": "./dist/index.cjs",
@@ -1,10 +1,10 @@
1
1
 
2
2
  export enum A_SignalFeatures {
3
- Emit = '_A_SignalFeatures_Emit',
3
+ Next = '_A_SignalFeatures_Next',
4
4
  }
5
5
 
6
6
 
7
7
 
8
- export enum A_SignalBusFeatures {
9
- Emit = '_A_SignalBusFeatures_Emit',
8
+ export enum A_SignalVectorFeatures {
9
+ Next = '_A_SignalVectorFeatures_Next',
10
10
  }
@@ -16,6 +16,9 @@ export type A_SignalConfig_Init = {
16
16
  * OR "A_RouterWatcher,A_ScopeWatcher,A_LoggerWatcher"
17
17
  */
18
18
  stringStructure?: string
19
+
20
+
21
+ propagateSignals?: boolean
19
22
  }
20
23
 
21
24
 
@@ -1,5 +1,5 @@
1
1
  import { A_Caller, A_Component, A_Context, A_Feature, A_Inject, A_Scope } from "@adaas/a-concept";
2
- import { A_SignalBusFeatures, A_SignalFeatures } from "../A-Signal.constants";
2
+ import { A_SignalFeatures } from "../A-Signal.constants";
3
3
  import { A_SignalState } from "../context/A-SignalState.context";
4
4
  import { A_SignalConfig } from "../context/A-SignalConfig.context";
5
5
  import { A_Config } from "../../A-Config/A-Config.context";
@@ -36,8 +36,9 @@ export class A_SignalBus extends A_Component {
36
36
  @A_Feature.Extend({
37
37
  scope: [A_Signal]
38
38
  })
39
- async [A_SignalFeatures.Emit](
39
+ async [A_SignalFeatures.Next](
40
40
  @A_Inject(A_Caller) signal: A_Signal,
41
+ @A_Inject(A_Scope) scope: A_Scope,
41
42
 
42
43
  @A_Inject(A_Config) globalConfig?: A_Config<['A_SIGNAL_VECTOR_STRUCTURE']>,
43
44
  @A_Inject(A_Logger) logger?: A_Logger,
@@ -89,38 +90,6 @@ export class A_SignalBus extends A_Component {
89
90
 
90
91
  const vector = state.toVector();
91
92
 
92
-
93
-
94
- const nextScope = new A_Scope({
95
- name: `A_SignalBus_Next_Scope_of_${this.constructor.name}`,
96
- entities: [vector]
97
- })
98
- .inherit(A_Context.scope(this));
99
-
100
-
101
- try {
102
-
103
- await this.call(A_SignalBusFeatures.Emit, nextScope);
104
-
105
- nextScope.destroy();
106
-
107
- } catch (error) {
108
-
109
- nextScope.destroy();
110
-
111
- throw error;
112
- }
93
+ await vector.next(scope);
113
94
  }
114
-
115
-
116
-
117
-
118
- getState(){
119
-
120
- }
121
-
122
-
123
-
124
-
125
-
126
95
  }
@@ -54,8 +54,8 @@ export class A_Signal<
54
54
  *
55
55
  * @param scope
56
56
  */
57
- async emit(scope: A_Scope) {
58
- await this.call(A_SignalFeatures.Emit, scope);
57
+ async next(scope: A_Scope) {
58
+ await this.call(A_SignalFeatures.Next, scope);
59
59
  }
60
60
 
61
61
 
@@ -1,6 +1,7 @@
1
- import { A_Entity, A_TYPES__Component_Constructor, A_TYPES__Entity_Constructor } from "@adaas/a-concept";
1
+ import { A_Entity, A_Scope, A_TYPES__Component_Constructor, A_TYPES__Entity_Constructor } from "@adaas/a-concept";
2
2
  import { A_SignalVector_Serialized, A_SignalVector_Init } from "../A-Signal.types";
3
3
  import { A_Signal } from "./A-Signal.entity";
4
+ import { A_SignalVectorFeatures } from "../A-Signal.constants";
4
5
 
5
6
 
6
7
  /**
@@ -57,6 +58,46 @@ export class A_SignalVector<
57
58
  }
58
59
 
59
60
 
61
+ /**
62
+ * Enables iteration over the signals in the vector.
63
+ *
64
+ * @returns
65
+ */
66
+ [Symbol.iterator](): Iterator<TSignals[number]> {
67
+ let pointer = 0;
68
+ const signals = this.structure.map((signalConstructor) => {
69
+ const signalIndex = this._signals.findIndex(s => s.constructor === signalConstructor);
70
+ return signalIndex !== -1 ? this._signals[signalIndex] : undefined;
71
+ }) as TSignals[number][];
72
+
73
+ return {
74
+ next(): IteratorResult<TSignals[number]> {
75
+ if (pointer < signals.length) {
76
+ return {
77
+ done: false,
78
+ value: signals[pointer++]
79
+ };
80
+ } else {
81
+ return {
82
+ done: true,
83
+ value: undefined as any
84
+ };
85
+ }
86
+ }
87
+ };
88
+ }
89
+
90
+
91
+ /**
92
+ * Emits the signal vector to the specified scope.
93
+ *
94
+ * @param scope
95
+ */
96
+ async next(scope: A_Scope): Promise<void> {
97
+ return await this.call(A_SignalVectorFeatures.Next, scope);
98
+ }
99
+
100
+
60
101
  /**
61
102
  * Checks if the vector contains a signal of the specified type.
62
103
  *
@@ -74,6 +115,11 @@ export class A_SignalVector<
74
115
  return this.structure.includes(signalConstructor);
75
116
  }
76
117
 
118
+ /**
119
+ * Retrieves the signal of the specified type from the vector.
120
+ *
121
+ * @param signal
122
+ */
77
123
  get(signal: A_Signal): Record<string, any> | undefined
78
124
  get(signalConstructor: A_TYPES__Component_Constructor<A_Signal>): Record<string, any> | undefined
79
125
  get(param1: A_Signal | A_TYPES__Component_Constructor<A_Signal>): Record<string, any> | undefined {
@@ -1,5 +1,5 @@
1
- import { A_Component, A_Concept, A_Container, A_Context, A_Feature, A_Inject, A_Scope } from "@adaas/a-concept";
2
- import { A_SignalBusFeatures, A_SignalFeatures } from "@adaas/a-utils/lib/A-Signal/A-Signal.constants";
1
+ import { A_Caller, A_Component, A_Concept, A_Container, A_Context, A_Feature, A_Inject, A_Scope } from "@adaas/a-concept";
2
+ import { A_SignalVectorFeatures } from "@adaas/a-utils/lib/A-Signal/A-Signal.constants";
3
3
  import { A_SignalBus } from "@adaas/a-utils/lib/A-Signal/components/A-SignalBus.component";
4
4
  import { A_SignalConfig } from "@adaas/a-utils/lib/A-Signal/context/A-SignalConfig.context";
5
5
  import { A_Signal } from "@adaas/a-utils/lib/A-Signal/entities/A-Signal.entity";
@@ -27,13 +27,13 @@ describe('A-Signal tests', () => {
27
27
  buttonId: 'submit-order'
28
28
  }
29
29
  })
30
- await signal.emit(scope)
30
+ await signal.next(scope)
31
31
  }
32
32
 
33
33
 
34
34
  @A_Feature.Extend()
35
- async [A_SignalBusFeatures.Emit](
36
- @A_Inject(A_SignalVector) vector: A_SignalVector
35
+ async [A_SignalVectorFeatures.Next](
36
+ @A_Inject(A_Caller) vector: A_SignalVector
37
37
  ) {
38
38
  result = vector;
39
39
  }
@@ -91,13 +91,13 @@ describe('A-Signal tests', () => {
91
91
  }
92
92
  })
93
93
 
94
- await signal.emit(scope)
94
+ await signal.next(scope)
95
95
  }
96
96
 
97
97
 
98
98
  @A_Feature.Extend()
99
- async [A_SignalBusFeatures.Emit](
100
- @A_Inject(A_SignalVector) vector: A_SignalVector
99
+ async [A_SignalVectorFeatures.Next](
100
+ @A_Inject(A_Caller) vector: A_SignalVector
101
101
  ) {
102
102
  result = vector;
103
103
  }