insite-subscriptions-react 1.0.147 → 2.0.0

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/README.md CHANGED
@@ -9,5 +9,5 @@ $ npm install insite-subscriptions-react
9
9
  Or
10
10
 
11
11
  ```sh
12
- $ yarn add insite-subscriptions-react
12
+ $ bun add insite-subscriptions-react
13
13
  ```
package/package.json CHANGED
@@ -1,31 +1,34 @@
1
1
  {
2
- "name": "insite-subscriptions-react",
3
- "version": "1.0.147",
4
- "description": "inSite subscriptions React components",
5
- "type": "module",
6
- "main": "./lib/index.js",
7
- "module": "./lib/index.js",
8
- "packageManager": "yarn@1.22.22",
9
- "scripts": {
10
- "test": "echo \"Error: no test specified\" && exit 1"
11
- },
12
- "repository": {
13
- "type": "git",
14
- "url": "git+https://github.com/nesvet/insite-subscriptions-react.git"
15
- },
16
- "keywords": [
17
- "insite",
18
- "subscriptions",
19
- "react"
20
- ],
21
- "author": "Eugene Nesvetaev <dev@nesvet.dev> (https://nesvet.dev/)",
22
- "license": "MIT",
23
- "dependencies": {
24
- "insite-subscriptions-client": "^1",
25
- "@nesvet/n": "^1",
26
- "react": "^18"
27
- },
28
- "devDependencies": {
29
- "@nesvet/eslint-config": "^1"
30
- }
2
+ "name": "insite-subscriptions-react",
3
+ "version": "2.0.0",
4
+ "description": "inSite subscriptions React components",
5
+ "type": "module",
6
+ "main": "./src/index.js",
7
+ "module": "./src/index.js",
8
+ "packageManager": "bun@1.1.26",
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
+ "insite-subscriptions-client": "^2",
26
+ "@nesvet/n": "^1.1.7",
27
+ "react": "~18.2.0"
28
+ },
29
+ "devDependencies": {
30
+ "@nesvet/eslint-config": "^2.0.25",
31
+ "@types/react": "^18.3.5",
32
+ "typescript": "^5.5.4"
33
+ }
31
34
  }
@@ -1,18 +1,42 @@
1
+ import { Component, type ReactNode } from "react";
1
2
  import {
2
3
  getSubscriptionSymbol,
3
4
  renewSymbol,
4
5
  subscribeSymbol,
5
6
  Subscription,
6
7
  SubscriptionArray,
8
+ SubscriptionArrayWithSubscription,
7
9
  SubscriptionMap,
10
+ SubscriptionMapWithSubscription,
8
11
  SubscriptionObject,
12
+ SubscriptionObjectWithSubscription,
9
13
  unsubscribeSymbol
10
14
  } from "insite-subscriptions-client";
11
- import { Component } from "react";
12
15
 
13
16
 
14
- export class SubscriptionComponent extends Component {
15
- constructor(props) {
17
+ type Value = SubscriptionArrayWithSubscription | SubscriptionMapWithSubscription | SubscriptionObjectWithSubscription;
18
+
19
+ type Props = {
20
+ map?: boolean;
21
+ array?: boolean;
22
+ publication: string;
23
+ params: unknown[];
24
+ Item?: SubscriptionMap["Item"];
25
+ valueRef: (value: Value) => void;
26
+ consistent?: boolean;
27
+ children?: (isActive: boolean, value: Value) => ReactNode;
28
+ onUpdate?: (value: Value) => void;
29
+ };
30
+
31
+ type State = {} | undefined;// eslint-disable-line @typescript-eslint/ban-types
32
+
33
+ function isValueSubscriptionMap(props: Props, value: Value): value is SubscriptionMapWithSubscription {
34
+ return props.map === true;
35
+ }
36
+
37
+
38
+ export class SubscriptionComponent extends Component<Props, State> {
39
+ constructor(props: Props) {
16
40
  super(props);
17
41
 
18
42
  const SubscriptionTarget =
@@ -26,7 +50,7 @@ export class SubscriptionComponent extends Component {
26
50
 
27
51
  this.value = target;
28
52
 
29
- if (props.map && props.Item)
53
+ if (isValueSubscriptionMap(props, target) && props.Item)
30
54
  target.Item = props.Item;
31
55
 
32
56
  props.valueRef?.(this.value);
@@ -38,6 +62,8 @@ export class SubscriptionComponent extends Component {
38
62
  undefined :
39
63
  {};
40
64
 
65
+ value;
66
+
41
67
  publicationSnapshot =
42
68
  this.props.consistent ?
43
69
  undefined :
@@ -47,7 +73,7 @@ export class SubscriptionComponent extends Component {
47
73
  return this.value[getSubscriptionSymbol]()?.isActive ?? false;
48
74
  }
49
75
 
50
- renew(publicationName, params) {
76
+ renew(publicationName: string, params: unknown[]) {
51
77
  return this.value[renewSymbol](publicationName, params);
52
78
  }
53
79
 
@@ -60,7 +86,7 @@ export class SubscriptionComponent extends Component {
60
86
  }
61
87
 
62
88
 
63
- shouldComponentUpdate = this.props.consistent ? undefined : nextProps => {
89
+ shouldComponentUpdate = this.props.consistent ? undefined : (nextProps: Props) => {
64
90
  const publicationSnapshot = JSON.stringify(nextProps.params) + nextProps.publication;
65
91
 
66
92
  if (this.publicationSnapshot === publicationSnapshot)
@@ -1,10 +1,29 @@
1
+ import { Component, ReactNode } from "react";
1
2
  import { noop } from "@nesvet/n";
2
- import { Subscription, SubscriptionGroup } from "insite-subscriptions-client";
3
- import { Component } from "react";
3
+ import {
4
+ Subscription,
5
+ SubscriptionGroup,
6
+ type Options as SubscriptionGroupOptions,
7
+ type SubscriptionGroupUnparsedDefinition,
8
+ type SubscriptionGroupValues
9
+ } from "insite-subscriptions-client";
4
10
 
5
11
 
6
- export class SubscriptionGroupComponent extends Component {
7
- constructor(props) {
12
+ type Props = {
13
+ definitions: SubscriptionGroupUnparsedDefinition[];
14
+ target: SubscriptionGroupOptions["target"];
15
+ debounce: SubscriptionGroupOptions["debounce"];
16
+ valuesRef: (values: SubscriptionGroupValues) => void;
17
+ consistent: boolean;
18
+ children: (isLoaded: boolean, values: SubscriptionGroupValues) => ReactNode;
19
+ onUpdate: (group: SubscriptionGroup) => void;
20
+ };
21
+
22
+ type State = {} | undefined;// eslint-disable-line @typescript-eslint/ban-types
23
+
24
+
25
+ export class SubscriptionGroupComponent extends Component<Props, State> {
26
+ constructor(props: Props) {
8
27
  super(props);
9
28
 
10
29
  this.group = new SubscriptionGroup(props.definitions, {
@@ -19,6 +38,8 @@ export class SubscriptionGroupComponent extends Component {
19
38
 
20
39
  }
21
40
 
41
+ group;
42
+
22
43
  state = this.props.consistent ? undefined : {};
23
44
 
24
45
  definitionsSnapshot = this.props.consistent ? undefined : JSON.stringify(this.props.definitions);
@@ -35,13 +56,13 @@ export class SubscriptionGroupComponent extends Component {
35
56
  return this.group.values;
36
57
  }
37
58
 
38
- redefine = definitions => this.group.redefine(definitions);
59
+ redefine = (definitions: SubscriptionGroupUnparsedDefinition[]) => this.group.redefine(definitions);
39
60
 
40
61
  subscribe = () => this.group.subscribe();
41
62
 
42
63
  unsubscribe = () => this.group.unsubscribe();
43
64
 
44
- shouldComponentUpdate = this.props.consistent ? undefined : nextProps => {
65
+ shouldComponentUpdate = this.props.consistent ? undefined : (nextProps: Props) => {
45
66
  if (this.props.target !== nextProps.target || this.props.debounce !== nextProps.debounce)
46
67
  this.group.applyOptions({ target: nextProps.target, debounceLimit: nextProps.debounce });
47
68
 
File without changes