insite-subscriptions-react 2.2.3 → 2.3.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/dist/Subscription.d.ts +5 -2
- package/dist/Subscription.d.ts.map +1 -1
- package/dist/Subscription.js +28 -16
- package/dist/SubscriptionGroup.d.ts +5 -2
- package/dist/SubscriptionGroup.d.ts.map +1 -1
- package/dist/SubscriptionGroup.js +28 -18
- package/package.json +32 -32
- package/src/Subscription.tsx +42 -24
- package/src/SubscriptionGroup.tsx +43 -27
package/dist/Subscription.d.ts
CHANGED
|
@@ -24,11 +24,14 @@ export declare class SubscriptionComponent extends Component<Props, State> {
|
|
|
24
24
|
renew(publicationName: string, params: unknown[]): void;
|
|
25
25
|
subscribe(): void;
|
|
26
26
|
unsubscribe(): void;
|
|
27
|
-
shouldComponentUpdate:
|
|
27
|
+
shouldComponentUpdate: typeof SubscriptionComponent.inconsistentShouldComponentUpdate | undefined;
|
|
28
28
|
render(): string | number | true | import("react").ReactElement<any, string | import("react").JSXElementConstructor<any>> | Iterable<ReactNode> | null;
|
|
29
|
-
handleUpdate
|
|
29
|
+
handleUpdate(): void;
|
|
30
30
|
componentDidMount(): void;
|
|
31
31
|
componentWillUnmount(): void;
|
|
32
|
+
static inconsistentShouldComponentUpdate(this: SubscriptionComponent, nextProps: Props): boolean;
|
|
33
|
+
static consistentHandleUpdate(this: SubscriptionComponent): void;
|
|
34
|
+
static inconsistentHandleUpdate(this: SubscriptionComponent): void;
|
|
32
35
|
static defaultProps: {
|
|
33
36
|
params: never[];
|
|
34
37
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Subscription.d.ts","sourceRoot":"","sources":["../src/Subscription.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,KAAK,SAAS,EAAE,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"Subscription.d.ts","sourceRoot":"","sources":["../src/Subscription.tsx"],"names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CAAC,sBAAsB,CAAC,IAAI,EAAE,qBAAqB;IAOzD,MAAM,CAAC,wBAAwB,CAAC,IAAI,EAAE,qBAAqB;IAO3D,MAAM,CAAC,YAAY;;MAEjB;IAEF,MAAM,CAAC,MAAM,6BAAuB;CAEpC"}
|
package/dist/Subscription.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Component } from "react";
|
|
2
|
+
import { noop } from "@nesvet/n";
|
|
2
3
|
import { getSubscriptionSymbol, renewSymbol, subscribeSymbol, Subscription, SubscriptionArray, SubscriptionMap, SubscriptionObject, unsubscribeSymbol } from "insite-subscriptions-client";
|
|
3
4
|
function isValueSubscriptionMap(props, value) {
|
|
4
5
|
return props.map === true;
|
|
@@ -35,31 +36,42 @@ export class SubscriptionComponent extends Component {
|
|
|
35
36
|
unsubscribe() {
|
|
36
37
|
return this.value[unsubscribeSymbol]();
|
|
37
38
|
}
|
|
38
|
-
shouldComponentUpdate = this.props.consistent ?
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
return true;
|
|
42
|
-
this.publicationSnapshot = publicationSnapshot;
|
|
43
|
-
this.renew(nextProps.publication, nextProps.params);
|
|
44
|
-
return false;
|
|
45
|
-
};
|
|
39
|
+
shouldComponentUpdate = this.props.consistent ?
|
|
40
|
+
undefined :
|
|
41
|
+
SubscriptionComponent.inconsistentShouldComponentUpdate;
|
|
46
42
|
render() {
|
|
47
43
|
return this.props.children?.(this.isActive, this.value) || null;
|
|
48
44
|
}
|
|
49
|
-
handleUpdate
|
|
45
|
+
handleUpdate() {
|
|
46
|
+
this.props.onUpdate?.(this.value);
|
|
47
|
+
}
|
|
50
48
|
componentDidMount() {
|
|
51
49
|
this.subscribe();
|
|
52
|
-
this.handleUpdate =
|
|
53
|
-
this.props.
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
this.props.onUpdate?.(this.value);
|
|
57
|
-
this.setState({});
|
|
58
|
-
};
|
|
50
|
+
this.handleUpdate =
|
|
51
|
+
this.props.consistent ?
|
|
52
|
+
SubscriptionComponent.consistentHandleUpdate :
|
|
53
|
+
SubscriptionComponent.inconsistentHandleUpdate;
|
|
59
54
|
}
|
|
60
55
|
componentWillUnmount() {
|
|
56
|
+
this.handleUpdate = noop;
|
|
61
57
|
this.unsubscribe();
|
|
62
58
|
}
|
|
59
|
+
static inconsistentShouldComponentUpdate(nextProps) {
|
|
60
|
+
const publicationSnapshot = JSON.stringify(nextProps.params) + nextProps.publication;
|
|
61
|
+
if (this.publicationSnapshot === publicationSnapshot)
|
|
62
|
+
return true;
|
|
63
|
+
this.publicationSnapshot = publicationSnapshot;
|
|
64
|
+
this.renew(nextProps.publication, nextProps.params);
|
|
65
|
+
return false;
|
|
66
|
+
}
|
|
67
|
+
static consistentHandleUpdate() {
|
|
68
|
+
this.props.onUpdate?.(this.value);
|
|
69
|
+
this.forceUpdate();
|
|
70
|
+
}
|
|
71
|
+
static inconsistentHandleUpdate() {
|
|
72
|
+
this.props.onUpdate?.(this.value);
|
|
73
|
+
this.setState({});
|
|
74
|
+
}
|
|
63
75
|
static defaultProps = {
|
|
64
76
|
params: []
|
|
65
77
|
};
|
|
@@ -22,11 +22,14 @@ export declare class SubscriptionGroupComponent extends Component<Props, State>
|
|
|
22
22
|
redefine: (definitions: SubscriptionGroupUnparsedDefinition[]) => Promise<(import("insite-subscriptions-client/dist/SubscriptionGroup/SubscriptionGroupItem").SubscriptionGroupItem<import("insite-subscriptions-client").SubscriptionGroupSubscriptionType, import("insite-subscriptions-client").SubscriptionGroupDefinition<import("insite-subscriptions-client").SubscriptionGroupSubscriptionType>> | import("insite-subscriptions-client/dist/SubscriptionGroup/SubscriptionGroupItem").SubscriptionGroupItem<import("insite-subscriptions-client").SubscriptionGroupSubscriptionType, import("insite-subscriptions-client").SubscriptionGroupDefinition<import("insite-subscriptions-client").SubscriptionGroupSubscriptionType>>[])[]>;
|
|
23
23
|
subscribe: () => void[];
|
|
24
24
|
unsubscribe: () => (void | undefined)[];
|
|
25
|
-
shouldComponentUpdate:
|
|
25
|
+
shouldComponentUpdate: typeof SubscriptionGroupComponent.inconsistentShouldComponentUpdate | undefined;
|
|
26
26
|
render(): string | number | true | import("react").ReactElement<any, string | import("react").JSXElementConstructor<any>> | Iterable<ReactNode> | null;
|
|
27
|
-
handleUpdate
|
|
27
|
+
handleUpdate(): void;
|
|
28
28
|
componentDidMount(): void;
|
|
29
29
|
componentWillUnmount(): void;
|
|
30
|
+
static inconsistentShouldComponentUpdate(this: SubscriptionGroupComponent, nextProps: Props): boolean;
|
|
31
|
+
static consistentHandleUpdate(this: SubscriptionGroupComponent): void;
|
|
32
|
+
static inconsistentHandleUpdate(this: SubscriptionGroupComponent): void;
|
|
30
33
|
static bindTo: typeof Subscription.bindTo;
|
|
31
34
|
}
|
|
32
35
|
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SubscriptionGroup.d.ts","sourceRoot":"","sources":["../src/SubscriptionGroup.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAE7C,OAAO,EACN,YAAY,EACZ,iBAAiB,EACjB,KAAK,wBAAwB,EAC7B,KAAK,mCAAmC,EACxC,MAAM,6BAA6B,CAAC;AAGrC,KAAK,uBAAuB,GAAG,GAAG,EAAE,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;AAE3D,KAAK,KAAK,GAAG;IACZ,WAAW,EAAE,mCAAmC,EAAE,CAAC;IACnD,MAAM,EAAE,wBAAwB,CAAC,QAAQ,CAAC,CAAC;IAC3C,QAAQ,EAAE,wBAAwB,CAAC,UAAU,CAAC,CAAC;IAC/C,SAAS,EAAE,CAAC,MAAM,EAAE,uBAAuB,KAAK,IAAI,CAAC;IACrD,UAAU,EAAE,OAAO,CAAC;IACpB,QAAQ,EAAE,CAAC,QAAQ,EAAE,OAAO,EAAE,MAAM,EAAE,uBAAuB,KAAK,SAAS,CAAC;IAC5E,QAAQ,EAAE,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M,GAAG,SAAS,CAAC;AAGhC,qBAAa,0BAA2B,SAAQ,SAAS,CAAC,KAAK,EAAE,KAAK,CAAC;gBAC1D,KAAK,EAAE,KAAK;IAexB,KAAK,2DAAC;IAEN,KAAK,iBAA0C;IAE/C,mBAAmB,qBAA8E;IAEjG,IAAI,QAAQ,YAEX;IAED,IAAI,QAAQ,YAEX;IAED,IAAI,MAAM,gCAET;IAED,QAAQ,GAAI,aAAa,mCAAmC,EAAE,kpBAAsC;IAEpG,SAAS,eAAgC;IAEzC,WAAW,6BAAkC;IAG7C,qBAAqB,kFAG0C;IAE/D,MAAM;IAKN,YAAY;IAMZ,iBAAiB;IAWjB,oBAAoB;IASpB,MAAM,CAAC,iCAAiC,CAAC,IAAI,EAAE,0BAA0B,EAAE,SAAS,EAAE,KAAK;IAe3F,MAAM,CAAC,sBAAsB,CAAC,IAAI,EAAE,0BAA0B;IAO9D,MAAM,CAAC,wBAAwB,CAAC,IAAI,EAAE,0BAA0B;IAOhE,MAAM,CAAC,MAAM,6BAAuB;CAEpC"}
|
|
@@ -27,33 +27,43 @@ export class SubscriptionGroupComponent extends Component {
|
|
|
27
27
|
redefine = (definitions) => this.group.redefine(definitions);
|
|
28
28
|
subscribe = () => this.group.subscribe();
|
|
29
29
|
unsubscribe = () => this.group.unsubscribe();
|
|
30
|
-
shouldComponentUpdate = this.props.consistent ?
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
const definitionsSnapshot = JSON.stringify(nextProps.definitions);
|
|
34
|
-
if (this.definitionsSnapshot === definitionsSnapshot)
|
|
35
|
-
return true;
|
|
36
|
-
this.definitionsSnapshot = definitionsSnapshot;
|
|
37
|
-
this.redefine(nextProps.definitions);
|
|
38
|
-
return false;
|
|
39
|
-
};
|
|
30
|
+
shouldComponentUpdate = this.props.consistent ?
|
|
31
|
+
undefined :
|
|
32
|
+
SubscriptionGroupComponent.inconsistentShouldComponentUpdate;
|
|
40
33
|
render() {
|
|
41
34
|
return this.props.children?.(this.group.isLoaded, this.group.values) || null;
|
|
42
35
|
}
|
|
43
|
-
handleUpdate
|
|
36
|
+
handleUpdate() {
|
|
37
|
+
this.props.onUpdate?.(this.group);
|
|
38
|
+
}
|
|
44
39
|
componentDidMount() {
|
|
45
40
|
this.subscribe();
|
|
46
|
-
this.handleUpdate =
|
|
47
|
-
this.props.
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
this.props.onUpdate?.(this.group);
|
|
51
|
-
this.setState({});
|
|
52
|
-
};
|
|
41
|
+
this.handleUpdate =
|
|
42
|
+
this.props.consistent ?
|
|
43
|
+
SubscriptionGroupComponent.consistentHandleUpdate :
|
|
44
|
+
SubscriptionGroupComponent.inconsistentHandleUpdate;
|
|
53
45
|
}
|
|
54
46
|
componentWillUnmount() {
|
|
55
47
|
this.handleUpdate = noop;
|
|
56
48
|
this.unsubscribe();
|
|
57
49
|
}
|
|
50
|
+
static inconsistentShouldComponentUpdate(nextProps) {
|
|
51
|
+
if (this.props.target !== nextProps.target || this.props.debounce !== nextProps.debounce)
|
|
52
|
+
this.group.applyOptions({ target: nextProps.target, debounceLimit: nextProps.debounce });
|
|
53
|
+
const definitionsSnapshot = JSON.stringify(nextProps.definitions);
|
|
54
|
+
if (this.definitionsSnapshot === definitionsSnapshot)
|
|
55
|
+
return true;
|
|
56
|
+
this.definitionsSnapshot = definitionsSnapshot;
|
|
57
|
+
void this.redefine(nextProps.definitions);
|
|
58
|
+
return false;
|
|
59
|
+
}
|
|
60
|
+
static consistentHandleUpdate() {
|
|
61
|
+
this.props.onUpdate?.(this.group);
|
|
62
|
+
this.forceUpdate();
|
|
63
|
+
}
|
|
64
|
+
static inconsistentHandleUpdate() {
|
|
65
|
+
this.props.onUpdate?.(this.group);
|
|
66
|
+
this.setState({});
|
|
67
|
+
}
|
|
58
68
|
static bindTo = Subscription.bindTo;
|
|
59
69
|
}
|
package/package.json
CHANGED
|
@@ -1,34 +1,34 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
2
|
+
"name": "insite-subscriptions-react",
|
|
3
|
+
"version": "2.3.3",
|
|
4
|
+
"description": "inSite subscriptions React components",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./src/index.js",
|
|
7
|
+
"module": "./src/index.js",
|
|
8
|
+
"packageManager": "bun@1.2.18",
|
|
9
|
+
"scripts": {
|
|
10
|
+
"test": "echo \"Error: no test specified\" && exit 1",
|
|
11
|
+
"build": "tsc -p ."
|
|
12
|
+
},
|
|
13
|
+
"repository": {
|
|
14
|
+
"type": "git",
|
|
15
|
+
"url": "git+https://github.com/nesvet/insite-subscriptions-react.git"
|
|
16
|
+
},
|
|
17
|
+
"keywords": [
|
|
18
|
+
"insite",
|
|
19
|
+
"subscriptions",
|
|
20
|
+
"react"
|
|
21
|
+
],
|
|
22
|
+
"author": "Eugene Nesvetaev <dev@nesvet.dev> (https://nesvet.dev/)",
|
|
23
|
+
"license": "MIT",
|
|
24
|
+
"dependencies": {
|
|
25
|
+
"@nesvet/n": "^1.2.1",
|
|
26
|
+
"insite-subscriptions-client": "^2.3.3",
|
|
27
|
+
"react": "~18.2.0"
|
|
28
|
+
},
|
|
29
|
+
"devDependencies": {
|
|
30
|
+
"@nesvet/eslint-config": "^2.1.2",
|
|
31
|
+
"@types/react": "^18.3.23",
|
|
32
|
+
"typescript": "^5.8.3"
|
|
33
|
+
}
|
|
34
34
|
}
|
package/src/Subscription.tsx
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Component, type ReactNode } from "react";
|
|
2
|
+
import { noop } from "@nesvet/n";
|
|
2
3
|
import {
|
|
3
4
|
getSubscriptionSymbol,
|
|
4
5
|
renewSymbol,
|
|
@@ -84,51 +85,68 @@ export class SubscriptionComponent extends Component<Props, State> {
|
|
|
84
85
|
}
|
|
85
86
|
|
|
86
87
|
|
|
87
|
-
shouldComponentUpdate =
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
return true;
|
|
92
|
-
|
|
93
|
-
this.publicationSnapshot = publicationSnapshot;
|
|
94
|
-
this.renew(nextProps.publication, nextProps.params);
|
|
95
|
-
|
|
96
|
-
return false;
|
|
97
|
-
|
|
98
|
-
};
|
|
88
|
+
shouldComponentUpdate =
|
|
89
|
+
this.props.consistent ?
|
|
90
|
+
undefined :
|
|
91
|
+
SubscriptionComponent.inconsistentShouldComponentUpdate;
|
|
99
92
|
|
|
100
93
|
render() {
|
|
101
94
|
return this.props.children?.(this.isActive, this.value) || null;
|
|
102
95
|
}
|
|
103
96
|
|
|
104
97
|
|
|
105
|
-
handleUpdate
|
|
98
|
+
handleUpdate() {
|
|
99
|
+
|
|
100
|
+
this.props.onUpdate?.(this.value);
|
|
101
|
+
|
|
102
|
+
}
|
|
106
103
|
|
|
107
104
|
componentDidMount() {
|
|
108
105
|
|
|
109
106
|
this.subscribe();
|
|
110
107
|
|
|
111
|
-
this.handleUpdate =
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
} : () => {
|
|
117
|
-
|
|
118
|
-
this.props.onUpdate?.(this.value);
|
|
119
|
-
this.setState({});
|
|
120
|
-
|
|
121
|
-
};
|
|
108
|
+
this.handleUpdate =
|
|
109
|
+
this.props.consistent ?
|
|
110
|
+
SubscriptionComponent.consistentHandleUpdate :
|
|
111
|
+
SubscriptionComponent.inconsistentHandleUpdate;
|
|
122
112
|
|
|
123
113
|
}
|
|
124
114
|
|
|
125
115
|
componentWillUnmount() {
|
|
126
116
|
|
|
117
|
+
this.handleUpdate = noop;
|
|
118
|
+
|
|
127
119
|
this.unsubscribe();
|
|
128
120
|
|
|
129
121
|
}
|
|
130
122
|
|
|
131
123
|
|
|
124
|
+
static inconsistentShouldComponentUpdate(this: SubscriptionComponent, nextProps: Props) {
|
|
125
|
+
const publicationSnapshot = JSON.stringify(nextProps.params) + nextProps.publication;
|
|
126
|
+
|
|
127
|
+
if (this.publicationSnapshot === publicationSnapshot)
|
|
128
|
+
return true;
|
|
129
|
+
|
|
130
|
+
this.publicationSnapshot = publicationSnapshot;
|
|
131
|
+
this.renew(nextProps.publication, nextProps.params);
|
|
132
|
+
|
|
133
|
+
return false;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
static consistentHandleUpdate(this: SubscriptionComponent) {
|
|
137
|
+
|
|
138
|
+
this.props.onUpdate?.(this.value);
|
|
139
|
+
this.forceUpdate();
|
|
140
|
+
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
static inconsistentHandleUpdate(this: SubscriptionComponent) {
|
|
144
|
+
|
|
145
|
+
this.props.onUpdate?.(this.value);
|
|
146
|
+
this.setState({});
|
|
147
|
+
|
|
148
|
+
}
|
|
149
|
+
|
|
132
150
|
static defaultProps = {
|
|
133
151
|
params: []
|
|
134
152
|
};
|
|
@@ -63,44 +63,31 @@ export class SubscriptionGroupComponent extends Component<Props, State> {
|
|
|
63
63
|
|
|
64
64
|
unsubscribe = () => this.group.unsubscribe();
|
|
65
65
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
if (this.definitionsSnapshot === definitionsSnapshot)
|
|
73
|
-
return true;
|
|
74
|
-
|
|
75
|
-
this.definitionsSnapshot = definitionsSnapshot;
|
|
76
|
-
this.redefine(nextProps.definitions);
|
|
77
|
-
|
|
78
|
-
return false;
|
|
79
|
-
|
|
80
|
-
};
|
|
66
|
+
|
|
67
|
+
shouldComponentUpdate =
|
|
68
|
+
this.props.consistent ?
|
|
69
|
+
undefined :
|
|
70
|
+
SubscriptionGroupComponent.inconsistentShouldComponentUpdate;
|
|
81
71
|
|
|
82
72
|
render() {
|
|
83
73
|
return this.props.children?.(this.group.isLoaded, this.group.values) || null;
|
|
84
74
|
}
|
|
85
75
|
|
|
86
76
|
|
|
87
|
-
handleUpdate
|
|
77
|
+
handleUpdate() {
|
|
78
|
+
|
|
79
|
+
this.props.onUpdate?.(this.group);
|
|
80
|
+
|
|
81
|
+
}
|
|
88
82
|
|
|
89
83
|
componentDidMount() {
|
|
90
84
|
|
|
91
85
|
this.subscribe();
|
|
92
86
|
|
|
93
|
-
this.handleUpdate =
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
} : () => {
|
|
99
|
-
|
|
100
|
-
this.props.onUpdate?.(this.group);
|
|
101
|
-
this.setState({});
|
|
102
|
-
|
|
103
|
-
};
|
|
87
|
+
this.handleUpdate =
|
|
88
|
+
this.props.consistent ?
|
|
89
|
+
SubscriptionGroupComponent.consistentHandleUpdate :
|
|
90
|
+
SubscriptionGroupComponent.inconsistentHandleUpdate;
|
|
104
91
|
|
|
105
92
|
}
|
|
106
93
|
|
|
@@ -113,6 +100,35 @@ export class SubscriptionGroupComponent extends Component<Props, State> {
|
|
|
113
100
|
}
|
|
114
101
|
|
|
115
102
|
|
|
103
|
+
static inconsistentShouldComponentUpdate(this: SubscriptionGroupComponent, nextProps: Props) {
|
|
104
|
+
if (this.props.target !== nextProps.target || this.props.debounce !== nextProps.debounce)
|
|
105
|
+
this.group.applyOptions({ target: nextProps.target, debounceLimit: nextProps.debounce });
|
|
106
|
+
|
|
107
|
+
const definitionsSnapshot = JSON.stringify(nextProps.definitions);
|
|
108
|
+
|
|
109
|
+
if (this.definitionsSnapshot === definitionsSnapshot)
|
|
110
|
+
return true;
|
|
111
|
+
|
|
112
|
+
this.definitionsSnapshot = definitionsSnapshot;
|
|
113
|
+
void this.redefine(nextProps.definitions);
|
|
114
|
+
|
|
115
|
+
return false;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
static consistentHandleUpdate(this: SubscriptionGroupComponent) {
|
|
119
|
+
|
|
120
|
+
this.props.onUpdate?.(this.group);
|
|
121
|
+
this.forceUpdate();
|
|
122
|
+
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
static inconsistentHandleUpdate(this: SubscriptionGroupComponent) {
|
|
126
|
+
|
|
127
|
+
this.props.onUpdate?.(this.group);
|
|
128
|
+
this.setState({});
|
|
129
|
+
|
|
130
|
+
}
|
|
131
|
+
|
|
116
132
|
static bindTo = Subscription.bindTo;
|
|
117
133
|
|
|
118
134
|
}
|