alemonjs 2.1.16-alpha.1 → 2.1.16-alpha.2
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/lib/app/SinglyLinkedList.d.ts +1 -5
- package/lib/app/SinglyLinkedList.js +1 -62
- package/lib/app/config.d.ts +0 -1
- package/lib/app/config.js +0 -1
- package/lib/app/event-processor-subscribe.js +26 -10
- package/lib/app/hook-use-subscribe.js +12 -4
- package/lib/types/subscribe/index.d.ts +2 -2
- package/package.json +1 -1
|
@@ -3,18 +3,14 @@ declare class ListNode<T> {
|
|
|
3
3
|
next: ListNode<T> | null;
|
|
4
4
|
constructor(data: T);
|
|
5
5
|
}
|
|
6
|
-
export declare class SinglyLinkedList<T
|
|
6
|
+
export declare class SinglyLinkedList<T> {
|
|
7
7
|
private head;
|
|
8
8
|
private size;
|
|
9
9
|
private current;
|
|
10
|
-
private indexMap;
|
|
11
10
|
constructor(initialValues?: T[]);
|
|
12
11
|
append(data: T): void;
|
|
13
|
-
findByKey<K extends keyof T>(key: K, value: T[K]): ListNode<T> | null;
|
|
14
|
-
updateById(id: any, updater: (data: T) => T): boolean;
|
|
15
12
|
popNext(): ListNode<T> | null;
|
|
16
13
|
removeCurrent(): void;
|
|
17
|
-
removeById(id: any): boolean;
|
|
18
14
|
getSize(): number;
|
|
19
15
|
}
|
|
20
16
|
export {};
|
|
@@ -10,12 +10,10 @@ class SinglyLinkedList {
|
|
|
10
10
|
head;
|
|
11
11
|
size;
|
|
12
12
|
current;
|
|
13
|
-
indexMap;
|
|
14
13
|
constructor(initialValues) {
|
|
15
14
|
this.head = null;
|
|
16
15
|
this.size = 0;
|
|
17
16
|
this.current = null;
|
|
18
|
-
this.indexMap = new Map();
|
|
19
17
|
if (initialValues) {
|
|
20
18
|
initialValues.forEach(value => this.append(value));
|
|
21
19
|
}
|
|
@@ -32,38 +30,8 @@ class SinglyLinkedList {
|
|
|
32
30
|
}
|
|
33
31
|
current.next = newNode;
|
|
34
32
|
}
|
|
35
|
-
if (data.id !== undefined) {
|
|
36
|
-
this.indexMap.set(data.id, newNode);
|
|
37
|
-
}
|
|
38
33
|
this.size++;
|
|
39
34
|
}
|
|
40
|
-
findByKey(key, value) {
|
|
41
|
-
if (key === 'id' && this.indexMap.has(value)) {
|
|
42
|
-
return this.indexMap.get(value);
|
|
43
|
-
}
|
|
44
|
-
let current = this.head;
|
|
45
|
-
while (current) {
|
|
46
|
-
if (current.data[key] === value) {
|
|
47
|
-
return current;
|
|
48
|
-
}
|
|
49
|
-
current = current.next;
|
|
50
|
-
}
|
|
51
|
-
return null;
|
|
52
|
-
}
|
|
53
|
-
updateById(id, updater) {
|
|
54
|
-
const node = this.findByKey('id', id);
|
|
55
|
-
if (!node) {
|
|
56
|
-
return false;
|
|
57
|
-
}
|
|
58
|
-
const oldData = node.data;
|
|
59
|
-
const newData = updater(oldData);
|
|
60
|
-
node.data = newData;
|
|
61
|
-
if (oldData.id !== newData.id) {
|
|
62
|
-
this.indexMap.delete(oldData.id);
|
|
63
|
-
this.indexMap.set(newData.id, node);
|
|
64
|
-
}
|
|
65
|
-
return true;
|
|
66
|
-
}
|
|
67
35
|
popNext() {
|
|
68
36
|
if (!this.current) {
|
|
69
37
|
this.current = this.head;
|
|
@@ -74,12 +42,9 @@ class SinglyLinkedList {
|
|
|
74
42
|
return this.current;
|
|
75
43
|
}
|
|
76
44
|
removeCurrent() {
|
|
77
|
-
if (!this.head
|
|
45
|
+
if (!this.head) {
|
|
78
46
|
return;
|
|
79
47
|
}
|
|
80
|
-
if (this.current.data.id !== undefined) {
|
|
81
|
-
this.indexMap.delete(this.current.data.id);
|
|
82
|
-
}
|
|
83
48
|
if (this.current === this.head) {
|
|
84
49
|
this.head = this.head.next;
|
|
85
50
|
this.current = null;
|
|
@@ -96,32 +61,6 @@ class SinglyLinkedList {
|
|
|
96
61
|
this.size--;
|
|
97
62
|
}
|
|
98
63
|
}
|
|
99
|
-
removeById(id) {
|
|
100
|
-
const node = this.findByKey('id', id);
|
|
101
|
-
if (!node) {
|
|
102
|
-
return false;
|
|
103
|
-
}
|
|
104
|
-
if (node === this.current) {
|
|
105
|
-
this.removeCurrent();
|
|
106
|
-
}
|
|
107
|
-
else {
|
|
108
|
-
if (node === this.head) {
|
|
109
|
-
this.head = node.next;
|
|
110
|
-
}
|
|
111
|
-
else {
|
|
112
|
-
let previous = this.head;
|
|
113
|
-
while (previous && previous.next !== node) {
|
|
114
|
-
previous = previous.next;
|
|
115
|
-
}
|
|
116
|
-
if (previous) {
|
|
117
|
-
previous.next = node.next;
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
this.indexMap.delete(id);
|
|
121
|
-
this.size--;
|
|
122
|
-
}
|
|
123
|
-
return true;
|
|
124
|
-
}
|
|
125
64
|
getSize() {
|
|
126
65
|
return this.size;
|
|
127
66
|
}
|
package/lib/app/config.d.ts
CHANGED
package/lib/app/config.js
CHANGED
|
@@ -9,12 +9,12 @@ const expendSubscribe = (valueEvent, select, next, choose) => {
|
|
|
9
9
|
return;
|
|
10
10
|
}
|
|
11
11
|
const item = subList.value.popNext();
|
|
12
|
-
const selects = item.data.selects;
|
|
13
|
-
const ID = item.data.id;
|
|
14
12
|
if (!item) {
|
|
15
13
|
nextObserver();
|
|
16
14
|
return;
|
|
17
15
|
}
|
|
16
|
+
const selects = item.data.selects;
|
|
17
|
+
const ID = item.data.id;
|
|
18
18
|
if (item.data.status === SubscribeStatus.paused) {
|
|
19
19
|
subList.value.removeCurrent();
|
|
20
20
|
nextObserver();
|
|
@@ -29,19 +29,35 @@ const expendSubscribe = (valueEvent, select, next, choose) => {
|
|
|
29
29
|
const onPaused = () => {
|
|
30
30
|
for (const select of selects) {
|
|
31
31
|
const subList = new SubscribeList(choose, select);
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
32
|
+
const find = () => {
|
|
33
|
+
const item = subList.value.popNext();
|
|
34
|
+
if (!item) {
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
if (item.data.id !== ID) {
|
|
38
|
+
find();
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
item.data.status = SubscribeStatus.paused;
|
|
42
|
+
};
|
|
43
|
+
find();
|
|
36
44
|
}
|
|
37
45
|
};
|
|
38
46
|
const onActive = () => {
|
|
39
47
|
for (const select of selects) {
|
|
40
48
|
const subList = new SubscribeList(choose, select);
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
49
|
+
const find = () => {
|
|
50
|
+
const item = subList.value.popNext();
|
|
51
|
+
if (!item) {
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
if (item.data.id !== ID) {
|
|
55
|
+
find();
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
item.data.status = SubscribeStatus.active;
|
|
59
|
+
};
|
|
60
|
+
find();
|
|
45
61
|
}
|
|
46
62
|
};
|
|
47
63
|
onPaused();
|
|
@@ -69,10 +69,18 @@ const useSubscribe = (event, selects) => {
|
|
|
69
69
|
const ID = value.id;
|
|
70
70
|
for (const select of selects) {
|
|
71
71
|
const subList = new SubscribeList(value.choose, select);
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
72
|
+
const find = () => {
|
|
73
|
+
const item = subList.value.popNext();
|
|
74
|
+
if (!item) {
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
if (item.data.id !== ID) {
|
|
78
|
+
find();
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
item.data.status = SubscribeStatus.paused;
|
|
82
|
+
};
|
|
83
|
+
find();
|
|
76
84
|
}
|
|
77
85
|
};
|
|
78
86
|
const subscribe = {
|
|
@@ -7,8 +7,8 @@ export type SubscribeValue = {
|
|
|
7
7
|
keys: {
|
|
8
8
|
[key: string]: string | number | boolean;
|
|
9
9
|
};
|
|
10
|
-
status?: 'active' | '
|
|
11
|
-
current:
|
|
10
|
+
status?: 'active' | 'paused';
|
|
11
|
+
current: (...arg: any[]) => any;
|
|
12
12
|
id: string;
|
|
13
13
|
};
|
|
14
14
|
export type SubscribeMap = Map<string, SinglyLinkedList<SubscribeValue>>;
|