evg_observable 2.15.1 → 2.15.3
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 +1 -1
- package/src/outLib/AbstractSwitchCase.d.ts +0 -29
- package/src/outLib/AbstractSwitchCase.js +0 -29
- package/src/outLib/Collector.d.ts +0 -45
- package/src/outLib/Collector.js +0 -45
- package/src/outLib/FilterCollection.d.ts +0 -53
- package/src/outLib/FilterCollection.js +0 -53
- package/src/outLib/FunctionLibs.d.ts +0 -42
- package/src/outLib/FunctionLibs.js +0 -48
- package/src/outLib/Observable.d.ts +0 -130
- package/src/outLib/Observable.js +0 -131
- package/src/outLib/OrderedObservable.d.ts +0 -59
- package/src/outLib/OrderedObservable.js +0 -59
- package/src/outLib/OrderedSubscribeObject.d.ts +0 -43
- package/src/outLib/OrderedSubscribeObject.js +0 -43
- package/src/outLib/Pipe.d.ts +0 -88
- package/src/outLib/Pipe.js +0 -81
- package/src/outLib/SubscribeObject.d.ts +0 -65
- package/src/outLib/SubscribeObject.js +0 -67
- package/src/outLib/Types.d.ts +0 -562
package/package.json
CHANGED
|
@@ -1,37 +1,8 @@
|
|
|
1
1
|
import { ICallback, IChainContainer } from "./Types";
|
|
2
|
-
/**
|
|
3
|
-
* Abstract class representing a Switch-Case control structure for handling
|
|
4
|
-
* conditional chains of operations.
|
|
5
|
-
*
|
|
6
|
-
* @template T - The type of the input payload expected by the conditions.
|
|
7
|
-
* @template P - The type extending IChainContainer, representing the container for the chain of operations.
|
|
8
|
-
* @template W - The type of the subclass or the expected return type for method chaining.
|
|
9
|
-
*/
|
|
10
2
|
export declare abstract class SwitchCase<T, P extends IChainContainer, W> {
|
|
11
3
|
protected pipe: P;
|
|
12
4
|
protected counter: number;
|
|
13
|
-
/**
|
|
14
|
-
* Creates an instance of the class and initializes the pipe and counter.
|
|
15
|
-
*
|
|
16
|
-
* @param {P} pipe - The pipe object used for initialization.
|
|
17
|
-
* @return {void}
|
|
18
|
-
*/
|
|
19
5
|
constructor(pipe: P);
|
|
20
|
-
/**
|
|
21
|
-
* Adds a conditional case to the processing chain. The case determines
|
|
22
|
-
* whether further processing should continue based on the provided condition.
|
|
23
|
-
*
|
|
24
|
-
* @param {ICallback<any>} condition - A callback function that takes a payload
|
|
25
|
-
* and evaluates a condition. If the condition is met, further processing may be stopped.
|
|
26
|
-
* @return {W} Returns the current instance for method chaining.
|
|
27
|
-
*/
|
|
28
6
|
case(condition: ICallback<any>): W;
|
|
29
|
-
/**
|
|
30
|
-
* Adds an array of conditions to the current instance by iterating through the provided array
|
|
31
|
-
* and adding each individual condition using the `case` method of the instance.
|
|
32
|
-
*
|
|
33
|
-
* @param {ICallback<any>[]} conditions - An array of callback functions representing conditions to be added.
|
|
34
|
-
* @return {W} The current instance after all conditions have been added.
|
|
35
|
-
*/
|
|
36
7
|
pushCases(conditions: ICallback<any>[]): W;
|
|
37
8
|
}
|
|
@@ -1,35 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.SwitchCase = void 0;
|
|
4
|
-
/**
|
|
5
|
-
* Abstract class representing a Switch-Case control structure for handling
|
|
6
|
-
* conditional chains of operations.
|
|
7
|
-
*
|
|
8
|
-
* @template T - The type of the input payload expected by the conditions.
|
|
9
|
-
* @template P - The type extending IChainContainer, representing the container for the chain of operations.
|
|
10
|
-
* @template W - The type of the subclass or the expected return type for method chaining.
|
|
11
|
-
*/
|
|
12
4
|
class SwitchCase {
|
|
13
5
|
pipe;
|
|
14
6
|
counter;
|
|
15
|
-
/**
|
|
16
|
-
* Creates an instance of the class and initializes the pipe and counter.
|
|
17
|
-
*
|
|
18
|
-
* @param {P} pipe - The pipe object used for initialization.
|
|
19
|
-
* @return {void}
|
|
20
|
-
*/
|
|
21
7
|
constructor(pipe) {
|
|
22
8
|
this.pipe = pipe;
|
|
23
9
|
this.counter = pipe.chain.length ? pipe.chain.length : 0;
|
|
24
10
|
}
|
|
25
|
-
/**
|
|
26
|
-
* Adds a conditional case to the processing chain. The case determines
|
|
27
|
-
* whether further processing should continue based on the provided condition.
|
|
28
|
-
*
|
|
29
|
-
* @param {ICallback<any>} condition - A callback function that takes a payload
|
|
30
|
-
* and evaluates a condition. If the condition is met, further processing may be stopped.
|
|
31
|
-
* @return {W} Returns the current instance for method chaining.
|
|
32
|
-
*/
|
|
33
11
|
case(condition) {
|
|
34
12
|
this.counter++;
|
|
35
13
|
const id = this.counter;
|
|
@@ -43,13 +21,6 @@ class SwitchCase {
|
|
|
43
21
|
});
|
|
44
22
|
return this;
|
|
45
23
|
}
|
|
46
|
-
/**
|
|
47
|
-
* Adds an array of conditions to the current instance by iterating through the provided array
|
|
48
|
-
* and adding each individual condition using the `case` method of the instance.
|
|
49
|
-
*
|
|
50
|
-
* @param {ICallback<any>[]} conditions - An array of callback functions representing conditions to be added.
|
|
51
|
-
* @return {W} The current instance after all conditions have been added.
|
|
52
|
-
*/
|
|
53
24
|
pushCases(conditions) {
|
|
54
25
|
if (!Array.isArray(conditions))
|
|
55
26
|
return this;
|
|
@@ -1,56 +1,11 @@
|
|
|
1
1
|
import { ICollector, ISubscriptionLike } from "./Types";
|
|
2
|
-
/**
|
|
3
|
-
* The Collector class is responsible for managing a collection of resources or subscription-like objects
|
|
4
|
-
* that need to be cleaned up or unsubscribed from, ensuring proper resource management.
|
|
5
|
-
* Implements the ICollector interface.
|
|
6
|
-
*
|
|
7
|
-
* The typical lifecycle of a Collector involves collecting subscription-like items, optionally
|
|
8
|
-
* unsubscribing from specific ones, unsubscribing from all resources, and destroying the collector
|
|
9
|
-
* when it's no longer needed.
|
|
10
|
-
*/
|
|
11
2
|
export declare class Collector implements ICollector {
|
|
12
3
|
protected arr: ISubscriptionLike[];
|
|
13
4
|
private killed;
|
|
14
|
-
/**
|
|
15
|
-
* Adds one or more subscription-like objects to the internal collection.
|
|
16
|
-
* Ensures the subscriptions are saved for future management if the object
|
|
17
|
-
* is not in a "killed" state.
|
|
18
|
-
*
|
|
19
|
-
* @param {ISubscriptionLike[]} subscriptionLikeList - The subscription-like objects to be collected.
|
|
20
|
-
* @return {void} This method does not return a value.
|
|
21
|
-
*/
|
|
22
5
|
collect(...subscriptionLikeList: ISubscriptionLike[]): void;
|
|
23
|
-
/**
|
|
24
|
-
* Unsubscribes a given subscription and removes it from the internal array.
|
|
25
|
-
*
|
|
26
|
-
* @param {ISubscriptionLike | undefined} subscriptionLike - The subscription to unsubscribe and remove. If undefined, no action is taken.
|
|
27
|
-
* @return {void} This method does not return a value.
|
|
28
|
-
*/
|
|
29
6
|
unsubscribe(subscriptionLike: ISubscriptionLike | undefined): void;
|
|
30
|
-
/**
|
|
31
|
-
* Unsubscribes from all the currently active subscriptions managed by this instance.
|
|
32
|
-
* If the instance is marked as killed, the method will exit without performing any action.
|
|
33
|
-
*
|
|
34
|
-
* @return {void | null} Returns `null` if the instance is killed, otherwise does not return a value.
|
|
35
|
-
*/
|
|
36
7
|
unsubscribeAll(): void | null;
|
|
37
|
-
/**
|
|
38
|
-
* Determines the size of the array managed by the instance.
|
|
39
|
-
* If the instance is marked as killed, the size is returned as 0.
|
|
40
|
-
*
|
|
41
|
-
* @return {number} The number of elements in the array, or 0 if the instance is killed.
|
|
42
|
-
*/
|
|
43
8
|
size(): number;
|
|
44
|
-
/**
|
|
45
|
-
* Cleans up resources by unsubscribing from all subscriptions, clearing the array, and marking the instance as destroyed.
|
|
46
|
-
*
|
|
47
|
-
* @return {void} Does not return any value.
|
|
48
|
-
*/
|
|
49
9
|
destroy(): void;
|
|
50
|
-
/**
|
|
51
|
-
* Checks if the object is destroyed.
|
|
52
|
-
*
|
|
53
|
-
* @return {boolean} Returns true if the object is destroyed, otherwise false.
|
|
54
|
-
*/
|
|
55
10
|
get isDestroyed(): boolean;
|
|
56
11
|
}
|
package/src/outLib/Collector.js
CHANGED
|
@@ -2,48 +2,19 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Collector = void 0;
|
|
4
4
|
const FunctionLibs_1 = require("./FunctionLibs");
|
|
5
|
-
/**
|
|
6
|
-
* The Collector class is responsible for managing a collection of resources or subscription-like objects
|
|
7
|
-
* that need to be cleaned up or unsubscribed from, ensuring proper resource management.
|
|
8
|
-
* Implements the ICollector interface.
|
|
9
|
-
*
|
|
10
|
-
* The typical lifecycle of a Collector involves collecting subscription-like items, optionally
|
|
11
|
-
* unsubscribing from specific ones, unsubscribing from all resources, and destroying the collector
|
|
12
|
-
* when it's no longer needed.
|
|
13
|
-
*/
|
|
14
5
|
class Collector {
|
|
15
6
|
arr = [];
|
|
16
7
|
killed = false;
|
|
17
|
-
/**
|
|
18
|
-
* Adds one or more subscription-like objects to the internal collection.
|
|
19
|
-
* Ensures the subscriptions are saved for future management if the object
|
|
20
|
-
* is not in a "killed" state.
|
|
21
|
-
*
|
|
22
|
-
* @param {ISubscriptionLike[]} subscriptionLikeList - The subscription-like objects to be collected.
|
|
23
|
-
* @return {void} This method does not return a value.
|
|
24
|
-
*/
|
|
25
8
|
collect(...subscriptionLikeList) {
|
|
26
9
|
if (!this.killed)
|
|
27
10
|
this.arr.push(...subscriptionLikeList);
|
|
28
11
|
}
|
|
29
|
-
/**
|
|
30
|
-
* Unsubscribes a given subscription and removes it from the internal array.
|
|
31
|
-
*
|
|
32
|
-
* @param {ISubscriptionLike | undefined} subscriptionLike - The subscription to unsubscribe and remove. If undefined, no action is taken.
|
|
33
|
-
* @return {void} This method does not return a value.
|
|
34
|
-
*/
|
|
35
12
|
unsubscribe(subscriptionLike) {
|
|
36
13
|
if (this.killed)
|
|
37
14
|
return;
|
|
38
15
|
subscriptionLike?.unsubscribe();
|
|
39
16
|
(0, FunctionLibs_1.quickDeleteFromArray)(this.arr, subscriptionLike);
|
|
40
17
|
}
|
|
41
|
-
/**
|
|
42
|
-
* Unsubscribes from all the currently active subscriptions managed by this instance.
|
|
43
|
-
* If the instance is marked as killed, the method will exit without performing any action.
|
|
44
|
-
*
|
|
45
|
-
* @return {void | null} Returns `null` if the instance is killed, otherwise does not return a value.
|
|
46
|
-
*/
|
|
47
18
|
unsubscribeAll() {
|
|
48
19
|
if (this.killed)
|
|
49
20
|
return;
|
|
@@ -52,33 +23,17 @@ class Collector {
|
|
|
52
23
|
arr[i].unsubscribe();
|
|
53
24
|
arr.length = 0;
|
|
54
25
|
}
|
|
55
|
-
/**
|
|
56
|
-
* Determines the size of the array managed by the instance.
|
|
57
|
-
* If the instance is marked as killed, the size is returned as 0.
|
|
58
|
-
*
|
|
59
|
-
* @return {number} The number of elements in the array, or 0 if the instance is killed.
|
|
60
|
-
*/
|
|
61
26
|
size() {
|
|
62
27
|
if (this.killed)
|
|
63
28
|
return 0;
|
|
64
29
|
return this.arr.length;
|
|
65
30
|
}
|
|
66
|
-
/**
|
|
67
|
-
* Cleans up resources by unsubscribing from all subscriptions, clearing the array, and marking the instance as destroyed.
|
|
68
|
-
*
|
|
69
|
-
* @return {void} Does not return any value.
|
|
70
|
-
*/
|
|
71
31
|
destroy() {
|
|
72
32
|
this.unsubscribeAll();
|
|
73
33
|
this.arr.length = 0;
|
|
74
34
|
this.arr = 0;
|
|
75
35
|
this.killed = true;
|
|
76
36
|
}
|
|
77
|
-
/**
|
|
78
|
-
* Checks if the object is destroyed.
|
|
79
|
-
*
|
|
80
|
-
* @return {boolean} Returns true if the object is destroyed, otherwise false.
|
|
81
|
-
*/
|
|
82
37
|
get isDestroyed() {
|
|
83
38
|
return this.killed;
|
|
84
39
|
}
|
|
@@ -1,70 +1,17 @@
|
|
|
1
1
|
import { ICallback, IErrorCallback, IFilter, IFilterCase, IFilterChainCallback, IFilterPayload, IFilterResponse, IFilterSetup, IFilterSwitch } from "./Types";
|
|
2
2
|
import { SwitchCase } from "./AbstractSwitchCase";
|
|
3
|
-
/**
|
|
4
|
-
* FilterCollection is a generic class implementing the IFilter and IFilterSwitch interfaces.
|
|
5
|
-
* It is designed to handle a series of filtering operations on a given payload, structured as a chain of filter methods.
|
|
6
|
-
* The class allows addition of filters, chaining of multiple filters, and provides mechanisms for handling payload processing flow.
|
|
7
|
-
*
|
|
8
|
-
* @template T The type of data that the filters will operate upon.
|
|
9
|
-
*/
|
|
10
3
|
export declare class FilterCollection<T> implements IFilter<T>, IFilterSwitch<T> {
|
|
11
4
|
chain: IFilterChainCallback[];
|
|
12
5
|
flow: IFilterPayload;
|
|
13
6
|
response: IFilterResponse;
|
|
14
7
|
private errHandler;
|
|
15
|
-
/**
|
|
16
|
-
* Determines whether the chain is empty.
|
|
17
|
-
* @return {boolean} Returns true if the chain contains no elements, otherwise false.
|
|
18
|
-
*/
|
|
19
8
|
get isEmpty(): boolean;
|
|
20
|
-
/**
|
|
21
|
-
* Adds a callback to the filter chain and returns the current instance.
|
|
22
|
-
*
|
|
23
|
-
* @param {IFilterChainCallback} callback - The callback function to be added to the filter chain.
|
|
24
|
-
* @return {IFilterSetup<T>} The current instance of IFilterSetup.
|
|
25
|
-
*/
|
|
26
9
|
private push;
|
|
27
|
-
/**
|
|
28
|
-
* Filters the data based on the given condition.
|
|
29
|
-
*
|
|
30
|
-
* @param {ICallback<any>} condition - A callback function that determines whether a data item should be included.
|
|
31
|
-
* Should return a truthy value to include the item.
|
|
32
|
-
* @return {IFilterSetup<T>} - The updated filter setup after applying the condition.
|
|
33
|
-
*/
|
|
34
10
|
filter(condition: ICallback<any>): IFilterSetup<T>;
|
|
35
|
-
/**
|
|
36
|
-
* Adds an array of filter conditions to the current filter setup.
|
|
37
|
-
*
|
|
38
|
-
* @param {ICallback<any>[]} conditions - An array of callback functions representing filter conditions.
|
|
39
|
-
* @return {IFilterSetup<T>} The updated filter setup instance.
|
|
40
|
-
*/
|
|
41
11
|
pushFilters(conditions: ICallback<any>[]): IFilterSetup<T>;
|
|
42
|
-
/**
|
|
43
|
-
* Creates and returns a new instance of the `FilterSwitchCase` class to handle switch case logic with the current context.
|
|
44
|
-
*
|
|
45
|
-
* @return {FilterSwitchCase<T>} A new instance of `FilterSwitchCase` initialized with the current context.
|
|
46
|
-
*/
|
|
47
12
|
switch(): FilterSwitchCase<T>;
|
|
48
|
-
/**
|
|
49
|
-
* Processes a chain of functions with the given input value and manages the execution flow through the chain.
|
|
50
|
-
*
|
|
51
|
-
* @param {T} value - The input value to be processed through the chain.
|
|
52
|
-
* @return {IFilterResponse} The final response containing the processing status and payload.
|
|
53
|
-
*/
|
|
54
13
|
processChain(value: T): IFilterResponse;
|
|
55
|
-
/**
|
|
56
|
-
* Assigns an error handler function to manage errors within the application.
|
|
57
|
-
*
|
|
58
|
-
* @param {IErrorCallback} errorHandler - A callback function that will handle error events.
|
|
59
|
-
* @return {void}
|
|
60
|
-
*/
|
|
61
14
|
addErrorHandler(errorHandler: IErrorCallback): void;
|
|
62
15
|
}
|
|
63
|
-
/**
|
|
64
|
-
* The FilterSwitchCase class extends the SwitchCase class and represents a specific type of switch case
|
|
65
|
-
* logic applied to a collection of filters. It is used for branching logic based on filter cases.
|
|
66
|
-
*
|
|
67
|
-
* @template T - The type of the elements being processed by the filters.
|
|
68
|
-
*/
|
|
69
16
|
export declare class FilterSwitchCase<T> extends SwitchCase<T, FilterCollection<T>, IFilterCase<T>> {
|
|
70
17
|
}
|
|
@@ -2,51 +2,21 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.FilterSwitchCase = exports.FilterCollection = void 0;
|
|
4
4
|
const AbstractSwitchCase_1 = require("./AbstractSwitchCase");
|
|
5
|
-
/**
|
|
6
|
-
* FilterCollection is a generic class implementing the IFilter and IFilterSwitch interfaces.
|
|
7
|
-
* It is designed to handle a series of filtering operations on a given payload, structured as a chain of filter methods.
|
|
8
|
-
* The class allows addition of filters, chaining of multiple filters, and provides mechanisms for handling payload processing flow.
|
|
9
|
-
*
|
|
10
|
-
* @template T The type of data that the filters will operate upon.
|
|
11
|
-
*/
|
|
12
5
|
class FilterCollection {
|
|
13
6
|
chain = [];
|
|
14
7
|
flow = { isBreak: false, isAvailable: false, payload: null };
|
|
15
8
|
response = { isOK: false, payload: undefined };
|
|
16
9
|
errHandler;
|
|
17
|
-
/**
|
|
18
|
-
* Determines whether the chain is empty.
|
|
19
|
-
* @return {boolean} Returns true if the chain contains no elements, otherwise false.
|
|
20
|
-
*/
|
|
21
10
|
get isEmpty() {
|
|
22
11
|
return !this.chain.length;
|
|
23
12
|
}
|
|
24
|
-
/**
|
|
25
|
-
* Adds a callback to the filter chain and returns the current instance.
|
|
26
|
-
*
|
|
27
|
-
* @param {IFilterChainCallback} callback - The callback function to be added to the filter chain.
|
|
28
|
-
* @return {IFilterSetup<T>} The current instance of IFilterSetup.
|
|
29
|
-
*/
|
|
30
13
|
push(callback) {
|
|
31
14
|
this.chain.push(callback);
|
|
32
15
|
return this;
|
|
33
16
|
}
|
|
34
|
-
/**
|
|
35
|
-
* Filters the data based on the given condition.
|
|
36
|
-
*
|
|
37
|
-
* @param {ICallback<any>} condition - A callback function that determines whether a data item should be included.
|
|
38
|
-
* Should return a truthy value to include the item.
|
|
39
|
-
* @return {IFilterSetup<T>} - The updated filter setup after applying the condition.
|
|
40
|
-
*/
|
|
41
17
|
filter(condition) {
|
|
42
18
|
return this.push((data) => condition(data.payload) && (data.isAvailable = true));
|
|
43
19
|
}
|
|
44
|
-
/**
|
|
45
|
-
* Adds an array of filter conditions to the current filter setup.
|
|
46
|
-
*
|
|
47
|
-
* @param {ICallback<any>[]} conditions - An array of callback functions representing filter conditions.
|
|
48
|
-
* @return {IFilterSetup<T>} The updated filter setup instance.
|
|
49
|
-
*/
|
|
50
20
|
pushFilters(conditions) {
|
|
51
21
|
if (!Array.isArray(conditions))
|
|
52
22
|
return this;
|
|
@@ -54,20 +24,9 @@ class FilterCollection {
|
|
|
54
24
|
this.filter(conditions[i]);
|
|
55
25
|
return this;
|
|
56
26
|
}
|
|
57
|
-
/**
|
|
58
|
-
* Creates and returns a new instance of the `FilterSwitchCase` class to handle switch case logic with the current context.
|
|
59
|
-
*
|
|
60
|
-
* @return {FilterSwitchCase<T>} A new instance of `FilterSwitchCase` initialized with the current context.
|
|
61
|
-
*/
|
|
62
27
|
switch() {
|
|
63
28
|
return new FilterSwitchCase(this);
|
|
64
29
|
}
|
|
65
|
-
/**
|
|
66
|
-
* Processes a chain of functions with the given input value and manages the execution flow through the chain.
|
|
67
|
-
*
|
|
68
|
-
* @param {T} value - The input value to be processed through the chain.
|
|
69
|
-
* @return {IFilterResponse} The final response containing the processing status and payload.
|
|
70
|
-
*/
|
|
71
30
|
processChain(value) {
|
|
72
31
|
const chain = this.chain;
|
|
73
32
|
const data = this.flow;
|
|
@@ -100,23 +59,11 @@ class FilterCollection {
|
|
|
100
59
|
response.payload = data.payload;
|
|
101
60
|
return response;
|
|
102
61
|
}
|
|
103
|
-
/**
|
|
104
|
-
* Assigns an error handler function to manage errors within the application.
|
|
105
|
-
*
|
|
106
|
-
* @param {IErrorCallback} errorHandler - A callback function that will handle error events.
|
|
107
|
-
* @return {void}
|
|
108
|
-
*/
|
|
109
62
|
addErrorHandler(errorHandler) {
|
|
110
63
|
this.errHandler = errorHandler;
|
|
111
64
|
}
|
|
112
65
|
}
|
|
113
66
|
exports.FilterCollection = FilterCollection;
|
|
114
|
-
/**
|
|
115
|
-
* The FilterSwitchCase class extends the SwitchCase class and represents a specific type of switch case
|
|
116
|
-
* logic applied to a collection of filters. It is used for branching logic based on filter cases.
|
|
117
|
-
*
|
|
118
|
-
* @template T - The type of the elements being processed by the filters.
|
|
119
|
-
*/
|
|
120
67
|
class FilterSwitchCase extends AbstractSwitchCase_1.SwitchCase {
|
|
121
68
|
}
|
|
122
69
|
exports.FilterSwitchCase = FilterSwitchCase;
|
|
@@ -1,48 +1,6 @@
|
|
|
1
1
|
import { IListener, ISubscribeGroup, ISubscribeObject } from "./Types";
|
|
2
|
-
/**
|
|
3
|
-
* Compares two ISubscribeObject items based on their `order` property
|
|
4
|
-
* and sorts them in ascending order.
|
|
5
|
-
*
|
|
6
|
-
* @param {ISubscribeObject<any>} a - The first object to compare.
|
|
7
|
-
* @param {ISubscribeObject<any>} b - The second object to compare.
|
|
8
|
-
* @return {number} - Returns 1 if the `order` property of `a` is greater than `b`,
|
|
9
|
-
* -1 if the `order` property of `a` is less than `b`,
|
|
10
|
-
* or 0 if they are equal.
|
|
11
|
-
*/
|
|
12
2
|
export declare function sortAscending(a: ISubscribeObject<any>, b: ISubscribeObject<any>): number;
|
|
13
|
-
/**
|
|
14
|
-
* Compares two objects based on their `order` property for descending sorting.
|
|
15
|
-
*
|
|
16
|
-
* @param {ISubscribeObject<any>} a - The first object to compare, expected to have an `order` property.
|
|
17
|
-
* @param {ISubscribeObject<any>} b - The second object to compare, expected to have an `order` property.
|
|
18
|
-
* @return {number} - Returns -1 if `a.order` is greater than `b.order`, 1 if `a.order` is less than `b.order`, and 0 if they are equal.
|
|
19
|
-
*/
|
|
20
3
|
export declare function sortDescending(a: ISubscribeObject<any>, b: ISubscribeObject<any>): number;
|
|
21
|
-
/**
|
|
22
|
-
* Removes the specified component from the provided array if it exists.
|
|
23
|
-
*
|
|
24
|
-
* @param {T[]} arr - The array from which the component will be removed.
|
|
25
|
-
* @param {T} component - The component to be removed from the array.
|
|
26
|
-
* @return {boolean} Returns true if the component was successfully removed, false otherwise.
|
|
27
|
-
*/
|
|
28
4
|
export declare function deleteFromArray<T>(arr: T[], component: T): boolean;
|
|
29
|
-
/**
|
|
30
|
-
* Removes a specified element from an array by replacing it with the last element
|
|
31
|
-
* and reducing the array's length. This method avoids maintaining order but performs
|
|
32
|
-
* the deletion operation efficiently.
|
|
33
|
-
*
|
|
34
|
-
* @param {T[]} arr - The array from which the element will be removed.
|
|
35
|
-
* @param {T} component - The element to be removed from the array.
|
|
36
|
-
* @return {boolean} - Returns true if the element was found and removed;
|
|
37
|
-
* otherwise, returns false.
|
|
38
|
-
*/
|
|
39
5
|
export declare function quickDeleteFromArray<T>(arr: T[], component: T): boolean;
|
|
40
|
-
/**
|
|
41
|
-
* Returns a listener function based on the provided listener group.
|
|
42
|
-
*
|
|
43
|
-
* @param {ISubscribeGroup<T>} listenerGroup - The group of listener(s). It can be a single listener
|
|
44
|
-
* or an array of listeners that are invoked when the returned listener is called.
|
|
45
|
-
* @return {IListener<T>} A single listener function that wraps the provided listener or group of listeners
|
|
46
|
-
* and invokes them with the provided data.
|
|
47
|
-
*/
|
|
48
6
|
export declare function getListener<T>(listenerGroup: ISubscribeGroup<T>): IListener<T>;
|
|
@@ -5,16 +5,6 @@ exports.sortDescending = sortDescending;
|
|
|
5
5
|
exports.deleteFromArray = deleteFromArray;
|
|
6
6
|
exports.quickDeleteFromArray = quickDeleteFromArray;
|
|
7
7
|
exports.getListener = getListener;
|
|
8
|
-
/**
|
|
9
|
-
* Compares two ISubscribeObject items based on their `order` property
|
|
10
|
-
* and sorts them in ascending order.
|
|
11
|
-
*
|
|
12
|
-
* @param {ISubscribeObject<any>} a - The first object to compare.
|
|
13
|
-
* @param {ISubscribeObject<any>} b - The second object to compare.
|
|
14
|
-
* @return {number} - Returns 1 if the `order` property of `a` is greater than `b`,
|
|
15
|
-
* -1 if the `order` property of `a` is less than `b`,
|
|
16
|
-
* or 0 if they are equal.
|
|
17
|
-
*/
|
|
18
8
|
function sortAscending(a, b) {
|
|
19
9
|
if (a.order > b.order)
|
|
20
10
|
return 1;
|
|
@@ -22,13 +12,6 @@ function sortAscending(a, b) {
|
|
|
22
12
|
return -1;
|
|
23
13
|
return 0;
|
|
24
14
|
}
|
|
25
|
-
/**
|
|
26
|
-
* Compares two objects based on their `order` property for descending sorting.
|
|
27
|
-
*
|
|
28
|
-
* @param {ISubscribeObject<any>} a - The first object to compare, expected to have an `order` property.
|
|
29
|
-
* @param {ISubscribeObject<any>} b - The second object to compare, expected to have an `order` property.
|
|
30
|
-
* @return {number} - Returns -1 if `a.order` is greater than `b.order`, 1 if `a.order` is less than `b.order`, and 0 if they are equal.
|
|
31
|
-
*/
|
|
32
15
|
function sortDescending(a, b) {
|
|
33
16
|
if (a.order > b.order)
|
|
34
17
|
return -1;
|
|
@@ -36,13 +19,6 @@ function sortDescending(a, b) {
|
|
|
36
19
|
return 1;
|
|
37
20
|
return 0;
|
|
38
21
|
}
|
|
39
|
-
/**
|
|
40
|
-
* Removes the specified component from the provided array if it exists.
|
|
41
|
-
*
|
|
42
|
-
* @param {T[]} arr - The array from which the component will be removed.
|
|
43
|
-
* @param {T} component - The component to be removed from the array.
|
|
44
|
-
* @return {boolean} Returns true if the component was successfully removed, false otherwise.
|
|
45
|
-
*/
|
|
46
22
|
function deleteFromArray(arr, component) {
|
|
47
23
|
const index = arr.indexOf(component);
|
|
48
24
|
if (index === -1)
|
|
@@ -50,16 +26,6 @@ function deleteFromArray(arr, component) {
|
|
|
50
26
|
arr.splice(index, 1);
|
|
51
27
|
return true;
|
|
52
28
|
}
|
|
53
|
-
/**
|
|
54
|
-
* Removes a specified element from an array by replacing it with the last element
|
|
55
|
-
* and reducing the array's length. This method avoids maintaining order but performs
|
|
56
|
-
* the deletion operation efficiently.
|
|
57
|
-
*
|
|
58
|
-
* @param {T[]} arr - The array from which the element will be removed.
|
|
59
|
-
* @param {T} component - The element to be removed from the array.
|
|
60
|
-
* @return {boolean} - Returns true if the element was found and removed;
|
|
61
|
-
* otherwise, returns false.
|
|
62
|
-
*/
|
|
63
29
|
function quickDeleteFromArray(arr, component) {
|
|
64
30
|
const index = arr.indexOf(component);
|
|
65
31
|
if (index === -1)
|
|
@@ -68,14 +34,6 @@ function quickDeleteFromArray(arr, component) {
|
|
|
68
34
|
arr.length--;
|
|
69
35
|
return true;
|
|
70
36
|
}
|
|
71
|
-
/**
|
|
72
|
-
* Returns a listener function based on the provided listener group.
|
|
73
|
-
*
|
|
74
|
-
* @param {ISubscribeGroup<T>} listenerGroup - The group of listener(s). It can be a single listener
|
|
75
|
-
* or an array of listeners that are invoked when the returned listener is called.
|
|
76
|
-
* @return {IListener<T>} A single listener function that wraps the provided listener or group of listeners
|
|
77
|
-
* and invokes them with the provided data.
|
|
78
|
-
*/
|
|
79
37
|
function getListener(listenerGroup) {
|
|
80
38
|
if (Array.isArray(listenerGroup)) {
|
|
81
39
|
const group = [];
|
|
@@ -88,12 +46,6 @@ function getListener(listenerGroup) {
|
|
|
88
46
|
}
|
|
89
47
|
return wrapListener(listenerGroup);
|
|
90
48
|
}
|
|
91
|
-
/**
|
|
92
|
-
* Wraps the provided listener, ensuring it conforms to the IListener<T> interface.
|
|
93
|
-
*
|
|
94
|
-
* @param listener The listener to be wrapped. Can be either an IListener<T> or an ISetObservableValue.
|
|
95
|
-
* @return Returns a listener that adheres to the IListener<T> interface.
|
|
96
|
-
*/
|
|
97
49
|
function wrapListener(listener) {
|
|
98
50
|
if ("next" in listener)
|
|
99
51
|
return (value) => listener.next(value);
|