polfan-server-js-client 0.2.54 → 0.2.55

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.
@@ -1,9 +1,7 @@
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;
5
4
  constructor(items?: [key: KeyT, value: ValueT][]);
6
- get mutationCounter(): number;
7
5
  get items(): Map<KeyT, ValueT>;
8
6
  get length(): number;
9
7
  set(...items: [KeyT, ValueT][]): void;
@@ -12,6 +10,7 @@ export declare class IndexedCollection<KeyT, ValueT> {
12
10
  delete(...ids: KeyT[]): void;
13
11
  deleteAll(): void;
14
12
  findBy(field: keyof ValueT, valueToFind: any, limit?: number): IndexedCollection<KeyT, ValueT>;
13
+ shallowCopy(): IndexedCollection<KeyT, ValueT>;
15
14
  }
16
15
  export declare class IndexedObjectCollection<T> {
17
16
  readonly id: keyof T | ((item: T) => any);
@@ -19,7 +18,6 @@ export declare class IndexedObjectCollection<T> {
19
18
  constructor(id: keyof T | ((item: T) => any), items?: T[]);
20
19
  get items(): T[];
21
20
  get length(): number;
22
- get mutationCounter(): number;
23
21
  set(...items: T[]): void;
24
22
  get(id: any): T | undefined;
25
23
  getAt(index: number): T | undefined;
@@ -27,6 +25,7 @@ export declare class IndexedObjectCollection<T> {
27
25
  delete(...ids: any[]): void;
28
26
  deleteAll(): void;
29
27
  findBy(field: keyof T, valueToFind: any, limit?: number): IndexedObjectCollection<T>;
28
+ shallowCopy(): IndexedObjectCollection<T>;
30
29
  protected getId(item: T): any;
31
30
  }
32
31
  interface ObservableCollectionEvent<KeyT> {
@@ -39,6 +38,7 @@ export declare class ObservableIndexedCollection<KeyT, ValueT> extends IndexedCo
39
38
  set(...items: [KeyT, ValueT][]): void;
40
39
  delete(...ids: KeyT[]): void;
41
40
  deleteAll(): void;
41
+ shallowCopy(): ObservableIndexedCollection<KeyT, ValueT>;
42
42
  on(eventName: 'change', handler: (ev?: ObservableCollectionEvent<KeyT>) => void): this;
43
43
  once(eventName: 'change', handler: (ev?: ObservableCollectionEvent<KeyT>) => void): this;
44
44
  off(eventName: string, handler: (ev?: ObservableCollectionEvent<KeyT>) => void): this;
@@ -50,6 +50,7 @@ export declare class ObservableIndexedObjectCollection<T> extends IndexedObjectC
50
50
  set(...items: T[]): void;
51
51
  delete(...ids: string[]): void;
52
52
  deleteAll(): void;
53
+ shallowCopy(): IndexedObjectCollection<T>;
53
54
  on(eventName: 'change', handler: (ev?: ObservableCollectionEvent<string>) => void): this;
54
55
  once(eventName: 'change', handler: (ev?: ObservableCollectionEvent<string>) => void): this;
55
56
  off(eventName: string, handler: (ev?: ObservableCollectionEvent<string>) => void): this;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "polfan-server-js-client",
3
- "version": "0.2.54",
3
+ "version": "0.2.55",
4
4
  "description": "JavaScript client library for handling communication with Polfan chat server.",
5
5
  "author": "Jarosław Żak",
6
6
  "license": "MIT",
@@ -2,16 +2,11 @@ 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;
6
5
 
7
6
  public constructor(items: [key: KeyT, value: ValueT][] = []) {
8
7
  this.set(...items);
9
8
  }
10
9
 
11
- public get mutationCounter(): number {
12
- return this._mutationCounter;
13
- }
14
-
15
10
  public get items(): Map<KeyT, ValueT> {
16
11
  return this._items;
17
12
  }
@@ -21,7 +16,6 @@ export class IndexedCollection<KeyT, ValueT> {
21
16
  }
22
17
 
23
18
  public set(...items: [KeyT, ValueT][]): void {
24
- this._mutationCounter++;
25
19
  for (const item of items) {
26
20
  this._items.set(item[0], item[1]);
27
21
  }
@@ -39,12 +33,10 @@ export class IndexedCollection<KeyT, ValueT> {
39
33
  for (const id of ids) {
40
34
  this.items.delete(id);
41
35
  }
42
- this._mutationCounter++;
43
36
  }
44
37
 
45
38
  public deleteAll(): void {
46
39
  this.items.clear();
47
- this._mutationCounter++;
48
40
  }
49
41
 
50
42
  public findBy(field: keyof ValueT, valueToFind: any, limit: number = null): IndexedCollection<KeyT, ValueT> {
@@ -60,6 +52,12 @@ export class IndexedCollection<KeyT, ValueT> {
60
52
  }
61
53
  return result;
62
54
  }
55
+
56
+ public shallowCopy(): IndexedCollection<KeyT, ValueT> {
57
+ const copy = new IndexedCollection<KeyT, ValueT>();
58
+ copy._items = this._items;
59
+ return copy;
60
+ }
63
61
  }
64
62
 
65
63
  export class IndexedObjectCollection<T> {
@@ -81,10 +79,6 @@ export class IndexedObjectCollection<T> {
81
79
  return this._items.length;
82
80
  }
83
81
 
84
- public get mutationCounter(): number {
85
- return this._items.mutationCounter;
86
- }
87
-
88
82
  public set(...items: T[]): void {
89
83
  this._items.set(...(items.map(item => [this.getId(item), item] as [string, T])));
90
84
  }
@@ -122,6 +116,12 @@ export class IndexedObjectCollection<T> {
122
116
  return result;
123
117
  }
124
118
 
119
+ public shallowCopy(): IndexedObjectCollection<T> {
120
+ const copy = new IndexedObjectCollection<T>(this.id);
121
+ copy._items = this._items;
122
+ return copy;
123
+ }
124
+
125
125
  protected getId(item: T): any {
126
126
  return typeof this.id === 'function' ? this.id(item) : item[this.id];
127
127
  }
@@ -163,6 +163,13 @@ export class ObservableIndexedCollection<KeyT, ValueT> extends IndexedCollection
163
163
  }
164
164
  }
165
165
 
166
+ public shallowCopy(): ObservableIndexedCollection<KeyT, ValueT> {
167
+ const copy = new ObservableIndexedCollection<KeyT, ValueT>();
168
+ copy.eventTarget = this.eventTarget;
169
+ copy._items = this._items;
170
+ return copy;
171
+ }
172
+
166
173
  public on(eventName: 'change', handler: (ev?: ObservableCollectionEvent<KeyT>) => void): this {
167
174
  this.eventTarget.on(eventName, handler);
168
175
  return this;
@@ -213,6 +220,13 @@ export class ObservableIndexedObjectCollection<T> extends IndexedObjectCollectio
213
220
  }
214
221
  }
215
222
 
223
+ public shallowCopy(): IndexedObjectCollection<T> {
224
+ const copy = new ObservableIndexedObjectCollection<T>(this.id);
225
+ copy.eventTarget = this.eventTarget;
226
+ copy._items = this._items;
227
+ return copy;
228
+ }
229
+
216
230
  public on(eventName: 'change', handler: (ev?: ObservableCollectionEvent<string>) => void): this {
217
231
  this.eventTarget.on(eventName, handler);
218
232
  return this;