polfan-server-js-client 0.1.99935 → 0.1.99936
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/.idea/workspace.xml +39 -25
- package/build/index.js +19 -19
- package/build/index.js.map +1 -1
- package/build/types/IndexedObjectCollection.d.ts +3 -2
- package/package.json +1 -1
- package/src/IndexedObjectCollection.ts +10 -8
- package/src/state-tracker/RoomsManager.ts +2 -2
- package/src/state-tracker/SpacesManager.ts +1 -1
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { EventTarget, ObservableInterface } from "./EventTarget";
|
|
2
2
|
export declare class IndexedCollection<KeyT, ValueT> {
|
|
3
3
|
protected _items: Map<KeyT, ValueT>;
|
|
4
|
+
protected _mutationCounter: number;
|
|
4
5
|
constructor(items?: [key: KeyT, value: ValueT][]);
|
|
6
|
+
get mutationCounter(): number;
|
|
5
7
|
get items(): Map<KeyT, ValueT>;
|
|
6
8
|
get length(): number;
|
|
7
9
|
set(...items: [KeyT, ValueT][]): void;
|
|
@@ -10,7 +12,6 @@ export declare class IndexedCollection<KeyT, ValueT> {
|
|
|
10
12
|
delete(...ids: KeyT[]): void;
|
|
11
13
|
deleteAll(): void;
|
|
12
14
|
findBy(field: keyof ValueT, valueToFind: any, limit?: number): IndexedCollection<KeyT, ValueT>;
|
|
13
|
-
map<MapT = any>(callback: (item: ValueT, index: KeyT) => MapT): MapT[];
|
|
14
15
|
}
|
|
15
16
|
export declare class IndexedObjectCollection<T> {
|
|
16
17
|
readonly id: keyof T | ((item: T) => any);
|
|
@@ -18,6 +19,7 @@ export declare class IndexedObjectCollection<T> {
|
|
|
18
19
|
constructor(id: keyof T | ((item: T) => any), items?: T[]);
|
|
19
20
|
get items(): T[];
|
|
20
21
|
get length(): number;
|
|
22
|
+
get mutationCounter(): number;
|
|
21
23
|
set(...items: T[]): void;
|
|
22
24
|
get(id: any): T | undefined;
|
|
23
25
|
getAt(index: number): T | undefined;
|
|
@@ -25,7 +27,6 @@ export declare class IndexedObjectCollection<T> {
|
|
|
25
27
|
delete(...ids: any[]): void;
|
|
26
28
|
deleteAll(): void;
|
|
27
29
|
findBy(field: keyof T, valueToFind: any, limit?: number): IndexedObjectCollection<T>;
|
|
28
|
-
map<MapT = any>(callback: (item: T, index: number, array: T[]) => MapT): MapT[];
|
|
29
30
|
protected getId(item: T): any;
|
|
30
31
|
}
|
|
31
32
|
interface ObservableCollectionEvent<KeyT> {
|
package/package.json
CHANGED
|
@@ -2,11 +2,16 @@ import {EventTarget, ObservableInterface} from "./EventTarget";
|
|
|
2
2
|
|
|
3
3
|
export class IndexedCollection<KeyT, ValueT> {
|
|
4
4
|
protected _items: Map<KeyT, ValueT> = new Map();
|
|
5
|
+
protected _mutationCounter: number = 0;
|
|
5
6
|
|
|
6
7
|
public constructor(items: [key: KeyT, value: ValueT][] = []) {
|
|
7
8
|
this.set(...items);
|
|
8
9
|
}
|
|
9
10
|
|
|
11
|
+
public get mutationCounter(): number {
|
|
12
|
+
return this._mutationCounter;
|
|
13
|
+
}
|
|
14
|
+
|
|
10
15
|
public get items(): Map<KeyT, ValueT> {
|
|
11
16
|
return this._items;
|
|
12
17
|
}
|
|
@@ -16,6 +21,7 @@ export class IndexedCollection<KeyT, ValueT> {
|
|
|
16
21
|
}
|
|
17
22
|
|
|
18
23
|
public set(...items: [KeyT, ValueT][]): void {
|
|
24
|
+
this._mutationCounter++;
|
|
19
25
|
for (const item of items) {
|
|
20
26
|
this._items.set(item[0], item[1]);
|
|
21
27
|
}
|
|
@@ -52,10 +58,6 @@ export class IndexedCollection<KeyT, ValueT> {
|
|
|
52
58
|
}
|
|
53
59
|
return result;
|
|
54
60
|
}
|
|
55
|
-
|
|
56
|
-
public map<MapT = any>(callback: (item: ValueT, index: KeyT) => MapT): MapT[] {
|
|
57
|
-
return Array.from(this.items.entries()).map((entry) => callback(entry[1], entry[0]));
|
|
58
|
-
}
|
|
59
61
|
}
|
|
60
62
|
|
|
61
63
|
export class IndexedObjectCollection<T> {
|
|
@@ -77,6 +79,10 @@ export class IndexedObjectCollection<T> {
|
|
|
77
79
|
return this._items.length;
|
|
78
80
|
}
|
|
79
81
|
|
|
82
|
+
public get mutationCounter(): number {
|
|
83
|
+
return this._items.mutationCounter;
|
|
84
|
+
}
|
|
85
|
+
|
|
80
86
|
public set(...items: T[]): void {
|
|
81
87
|
this._items.set(...(items.map(item => [this.getId(item), item] as [string, T])));
|
|
82
88
|
}
|
|
@@ -114,10 +120,6 @@ export class IndexedObjectCollection<T> {
|
|
|
114
120
|
return result;
|
|
115
121
|
}
|
|
116
122
|
|
|
117
|
-
public map<MapT = any>(callback: (item: T, index: number, array: T[]) => MapT): MapT[] {
|
|
118
|
-
return this.items.map(callback);
|
|
119
|
-
}
|
|
120
|
-
|
|
121
123
|
protected getId(item: T): any {
|
|
122
124
|
return typeof this.id === 'function' ? this.id(item) : item[this.id];
|
|
123
125
|
}
|
|
@@ -124,7 +124,7 @@ export class RoomsManager {
|
|
|
124
124
|
this.membersPromises.forget(...roomIds);
|
|
125
125
|
|
|
126
126
|
for (const roomId of roomIds) {
|
|
127
|
-
const topicIds: string[] = this.topics.get(roomId)?.map(topic => topic.id) ?? [];
|
|
127
|
+
const topicIds: string[] = this.topics.get(roomId)?.items.map(topic => topic.id) ?? [];
|
|
128
128
|
this.messages._deleteByTopicIds(roomId, ...topicIds);
|
|
129
129
|
}
|
|
130
130
|
|
|
@@ -133,7 +133,7 @@ export class RoomsManager {
|
|
|
133
133
|
|
|
134
134
|
private deleteRoomsBySpaceId(spaceId: string): void {
|
|
135
135
|
this.deleteRoom(
|
|
136
|
-
...this.list.findBy('spaceId', spaceId).map(room => room.id)
|
|
136
|
+
...this.list.findBy('spaceId', spaceId).items.map(room => room.id)
|
|
137
137
|
);
|
|
138
138
|
}
|
|
139
139
|
|
|
@@ -184,7 +184,7 @@ export class SpacesManager {
|
|
|
184
184
|
}
|
|
185
185
|
|
|
186
186
|
private handleSpaceDeleted(ev: SpaceDeleted | SpaceLeft): void {
|
|
187
|
-
const roomIds = this.rooms.get(ev.id)?.map(item => item.id) ?? [];
|
|
187
|
+
const roomIds = this.rooms.get(ev.id)?.items.map(item => item.id) ?? [];
|
|
188
188
|
this.roomIdToSpaceId.delete(...roomIds);
|
|
189
189
|
|
|
190
190
|
this.roles.delete(ev.id);
|