stream-chat 9.6.0 → 9.6.1
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/dist/cjs/index.browser.cjs +27 -16
- package/dist/cjs/index.browser.cjs.map +3 -3
- package/dist/cjs/index.node.cjs +30 -19
- package/dist/cjs/index.node.cjs.map +3 -3
- package/dist/esm/index.js +27 -16
- package/dist/esm/index.js.map +3 -3
- package/dist/types/utils/WithSubscriptions.d.ts +7 -2
- package/package.json +1 -1
- package/src/messageComposer/messageComposer.ts +16 -18
- package/src/utils/WithSubscriptions.ts +16 -2
|
@@ -10,14 +10,19 @@ export declare abstract class WithSubscriptions {
|
|
|
10
10
|
* overriding `unregisterSubscriptions` call the base method and return
|
|
11
11
|
* its unique symbol value.
|
|
12
12
|
*/
|
|
13
|
-
|
|
13
|
+
protected static symbol: symbol;
|
|
14
|
+
private refCount;
|
|
14
15
|
abstract registerSubscriptions(): void;
|
|
15
16
|
/**
|
|
16
17
|
* Returns a boolean, provides information of whether `registerSubscriptions`
|
|
17
18
|
* method has already been called for this instance.
|
|
18
19
|
*/
|
|
19
20
|
get hasSubscriptions(): boolean;
|
|
20
|
-
addUnsubscribeFunction(unsubscribeFunction: Unsubscribe): void;
|
|
21
|
+
protected addUnsubscribeFunction(unsubscribeFunction: Unsubscribe): void;
|
|
22
|
+
/**
|
|
23
|
+
* Increments `refCount` by one and returns new value.
|
|
24
|
+
*/
|
|
25
|
+
protected incrementRefCount(): number;
|
|
21
26
|
/**
|
|
22
27
|
* If you re-declare `unregisterSubscriptions` method within your class
|
|
23
28
|
* make sure to run the original too.
|
package/package.json
CHANGED
|
@@ -114,8 +114,6 @@ const initState = (
|
|
|
114
114
|
};
|
|
115
115
|
};
|
|
116
116
|
|
|
117
|
-
const noop = () => undefined;
|
|
118
|
-
|
|
119
117
|
export class MessageComposer extends WithSubscriptions {
|
|
120
118
|
readonly channel: Channel;
|
|
121
119
|
readonly state: StateStore<MessageComposerState>;
|
|
@@ -363,23 +361,23 @@ export class MessageComposer extends WithSubscriptions {
|
|
|
363
361
|
}
|
|
364
362
|
|
|
365
363
|
public registerSubscriptions = (): UnregisterSubscriptions => {
|
|
366
|
-
if (this.hasSubscriptions) {
|
|
367
|
-
|
|
368
|
-
|
|
364
|
+
if (!this.hasSubscriptions) {
|
|
365
|
+
this.addUnsubscribeFunction(this.subscribeMessageComposerSetupStateChange());
|
|
366
|
+
this.addUnsubscribeFunction(this.subscribeMessageUpdated());
|
|
367
|
+
this.addUnsubscribeFunction(this.subscribeMessageDeleted());
|
|
368
|
+
|
|
369
|
+
this.addUnsubscribeFunction(this.subscribeTextComposerStateChanged());
|
|
370
|
+
this.addUnsubscribeFunction(this.subscribeAttachmentManagerStateChanged());
|
|
371
|
+
this.addUnsubscribeFunction(this.subscribeLinkPreviewsManagerStateChanged());
|
|
372
|
+
this.addUnsubscribeFunction(this.subscribePollComposerStateChanged());
|
|
373
|
+
this.addUnsubscribeFunction(this.subscribeCustomDataManagerStateChanged());
|
|
374
|
+
this.addUnsubscribeFunction(this.subscribeMessageComposerStateChanged());
|
|
375
|
+
this.addUnsubscribeFunction(this.subscribeMessageComposerConfigStateChanged());
|
|
369
376
|
}
|
|
370
|
-
|
|
371
|
-
this.
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
this.addUnsubscribeFunction(this.subscribeTextComposerStateChanged());
|
|
375
|
-
this.addUnsubscribeFunction(this.subscribeAttachmentManagerStateChanged());
|
|
376
|
-
this.addUnsubscribeFunction(this.subscribeLinkPreviewsManagerStateChanged());
|
|
377
|
-
this.addUnsubscribeFunction(this.subscribePollComposerStateChanged());
|
|
378
|
-
this.addUnsubscribeFunction(this.subscribeCustomDataManagerStateChanged());
|
|
379
|
-
this.addUnsubscribeFunction(this.subscribeMessageComposerStateChanged());
|
|
380
|
-
this.addUnsubscribeFunction(this.subscribeMessageComposerConfigStateChanged());
|
|
381
|
-
|
|
382
|
-
return this.unregisterSubscriptions.bind(this);
|
|
377
|
+
|
|
378
|
+
this.incrementRefCount();
|
|
379
|
+
|
|
380
|
+
return () => this.unregisterSubscriptions();
|
|
383
381
|
};
|
|
384
382
|
|
|
385
383
|
private subscribeMessageUpdated = () => {
|
|
@@ -11,7 +11,8 @@ export abstract class WithSubscriptions {
|
|
|
11
11
|
* overriding `unregisterSubscriptions` call the base method and return
|
|
12
12
|
* its unique symbol value.
|
|
13
13
|
*/
|
|
14
|
-
|
|
14
|
+
protected static symbol = Symbol(WithSubscriptions.name);
|
|
15
|
+
private refCount = 0;
|
|
15
16
|
|
|
16
17
|
public abstract registerSubscriptions(): void;
|
|
17
18
|
|
|
@@ -23,10 +24,17 @@ export abstract class WithSubscriptions {
|
|
|
23
24
|
return this.unsubscribeFunctions.size > 0;
|
|
24
25
|
}
|
|
25
26
|
|
|
26
|
-
|
|
27
|
+
protected addUnsubscribeFunction(unsubscribeFunction: Unsubscribe) {
|
|
27
28
|
this.unsubscribeFunctions.add(unsubscribeFunction);
|
|
28
29
|
}
|
|
29
30
|
|
|
31
|
+
/**
|
|
32
|
+
* Increments `refCount` by one and returns new value.
|
|
33
|
+
*/
|
|
34
|
+
protected incrementRefCount() {
|
|
35
|
+
return ++this.refCount;
|
|
36
|
+
}
|
|
37
|
+
|
|
30
38
|
/**
|
|
31
39
|
* If you re-declare `unregisterSubscriptions` method within your class
|
|
32
40
|
* make sure to run the original too.
|
|
@@ -43,8 +51,14 @@ export abstract class WithSubscriptions {
|
|
|
43
51
|
* ```
|
|
44
52
|
*/
|
|
45
53
|
public unregisterSubscriptions(): typeof WithSubscriptions.symbol {
|
|
54
|
+
if (this.refCount > 1) {
|
|
55
|
+
this.refCount--;
|
|
56
|
+
return WithSubscriptions.symbol;
|
|
57
|
+
}
|
|
58
|
+
|
|
46
59
|
this.unsubscribeFunctions.forEach((unsubscribe) => unsubscribe());
|
|
47
60
|
this.unsubscribeFunctions.clear();
|
|
61
|
+
this.refCount = 0;
|
|
48
62
|
|
|
49
63
|
return WithSubscriptions.symbol;
|
|
50
64
|
}
|