insite-subscriptions-client 1.0.294
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/LICENSE +21 -0
- package/README.md +13 -0
- package/lib/Subscription.js +106 -0
- package/lib/SubscriptionArray.js +241 -0
- package/lib/SubscriptionGroup/SubscriptionGroup.js +292 -0
- package/lib/SubscriptionGroup/SubscriptionGroupItem.js +300 -0
- package/lib/SubscriptionGroup/common.js +1 -0
- package/lib/SubscriptionGroup/index.js +1 -0
- package/lib/SubscriptionMap.js +393 -0
- package/lib/SubscriptionObject.js +153 -0
- package/lib/index.js +21 -0
- package/lib/symbols.js +12 -0
- package/package.json +35 -0
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
import { Subscription } from "./Subscription";
|
|
2
|
+
import {
|
|
3
|
+
clearSymbol,
|
|
4
|
+
getAsInitialUpdatedSymbol,
|
|
5
|
+
getAsUpdatesSymbol,
|
|
6
|
+
getHandleUpdateSymbol,
|
|
7
|
+
getSubscriptionSymbol,
|
|
8
|
+
renewSymbol,
|
|
9
|
+
setHandleUpdateSymbol,
|
|
10
|
+
subscribeSymbol,
|
|
11
|
+
unsubscribeSymbol,
|
|
12
|
+
updateSymbol
|
|
13
|
+
} from "./symbols";
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
export class SubscriptionObject {
|
|
17
|
+
#handleUpdate;
|
|
18
|
+
|
|
19
|
+
constructor(updates, onUpdate) {
|
|
20
|
+
this.#handleUpdate = onUpdate;
|
|
21
|
+
|
|
22
|
+
if (updates)
|
|
23
|
+
this[updateSymbol](updates);
|
|
24
|
+
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
#updates = null;
|
|
28
|
+
|
|
29
|
+
[getHandleUpdateSymbol]() {
|
|
30
|
+
return this.#handleUpdate;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
[setHandleUpdateSymbol](handleUpdate) {
|
|
34
|
+
return (this.#handleUpdate = handleUpdate);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
[updateSymbol](updates) {
|
|
38
|
+
if (updates) {
|
|
39
|
+
for (const key in this.#updates)
|
|
40
|
+
delete this[key];
|
|
41
|
+
for (const key in updates)
|
|
42
|
+
this[key] = updates[key];
|
|
43
|
+
this.#updates = updates;
|
|
44
|
+
} else
|
|
45
|
+
this[clearSymbol]();
|
|
46
|
+
|
|
47
|
+
this.#handleUpdate?.(this, this, this.#updates);
|
|
48
|
+
|
|
49
|
+
return this;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
[getAsUpdatesSymbol]() {
|
|
53
|
+
return this.#updates && { ...this.#updates };
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
[getAsInitialUpdatedSymbol]() {
|
|
57
|
+
return this.valueOf();
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
[clearSymbol]() {
|
|
61
|
+
|
|
62
|
+
for (const key in this)
|
|
63
|
+
delete this[key];
|
|
64
|
+
this.#updates = null;
|
|
65
|
+
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
valueOf() {
|
|
69
|
+
return this.#updates && this;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
get [Symbol.toStringTag]() {
|
|
73
|
+
return "SubscriptionObject";
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
static updateSymbol = updateSymbol;
|
|
78
|
+
static getHandleUpdateSymbol = getHandleUpdateSymbol;
|
|
79
|
+
static setHandleUpdateSymbol = setHandleUpdateSymbol;
|
|
80
|
+
static getAsUpdatesSymbol = getAsUpdatesSymbol;
|
|
81
|
+
static getAsInitialUpdatedSymbol = getAsInitialUpdatedSymbol;
|
|
82
|
+
static clearSymbol = clearSymbol;
|
|
83
|
+
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
SubscriptionObject.WithSubscription = class SubscriptionObjectWithSubscription extends SubscriptionObject {
|
|
88
|
+
#publicationName;
|
|
89
|
+
#params;
|
|
90
|
+
|
|
91
|
+
constructor(publicationName, params, onUpdate, immediately = true) {
|
|
92
|
+
super(null, onUpdate);
|
|
93
|
+
|
|
94
|
+
this.#publicationName = publicationName;
|
|
95
|
+
this.#params = params;
|
|
96
|
+
|
|
97
|
+
if (immediately)
|
|
98
|
+
this[subscribeSymbol]();
|
|
99
|
+
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
#subscription = null;
|
|
103
|
+
|
|
104
|
+
[subscribeSymbol]() {
|
|
105
|
+
|
|
106
|
+
if (!this.#subscription)
|
|
107
|
+
this.#subscription = new Subscription("object", this.#publicationName, this.#params, updates => this[updateSymbol](updates));
|
|
108
|
+
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
[unsubscribeSymbol]() {
|
|
112
|
+
|
|
113
|
+
if (this.#subscription) {
|
|
114
|
+
this.#subscription.cancel();
|
|
115
|
+
this.#subscription = null;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
[renewSymbol](publicationName, params) {
|
|
121
|
+
|
|
122
|
+
if (this.#subscription) {
|
|
123
|
+
this[unsubscribeSymbol]();
|
|
124
|
+
|
|
125
|
+
if (publicationName)
|
|
126
|
+
if (Array.isArray(publicationName))
|
|
127
|
+
params = publicationName;
|
|
128
|
+
else
|
|
129
|
+
this.#publicationName = publicationName;
|
|
130
|
+
|
|
131
|
+
if (params)
|
|
132
|
+
this.#params = params;
|
|
133
|
+
|
|
134
|
+
this[subscribeSymbol]();
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
[getSubscriptionSymbol]() {
|
|
140
|
+
return this.#subscription;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
get [Symbol.toStringTag]() {
|
|
144
|
+
return "SubscriptionObjectWithSubscription";
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
static subscribeSymbol = subscribeSymbol;
|
|
149
|
+
static unsubscribeSymbol = unsubscribeSymbol;
|
|
150
|
+
static renewSymbol = renewSymbol;
|
|
151
|
+
static getSubscriptionSymbol = getSubscriptionSymbol;
|
|
152
|
+
|
|
153
|
+
};
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
//#if _SSR
|
|
2
|
+
// export { default as Subscription, initialsMap, subscriptionContext } from "./Subscription.js";
|
|
3
|
+
//#else
|
|
4
|
+
export * from "./Subscription.js";
|
|
5
|
+
export * from "./SubscriptionArray";
|
|
6
|
+
export * from "./SubscriptionGroup";
|
|
7
|
+
export * from "./SubscriptionMap";
|
|
8
|
+
export * from "./SubscriptionObject";
|
|
9
|
+
export { clearSymbol,
|
|
10
|
+
getAsInitialUpdatedSymbol,
|
|
11
|
+
getAsUpdatesSymbol,
|
|
12
|
+
getHandleSubscriptionSymbol,
|
|
13
|
+
getHandleUpdateSymbol,
|
|
14
|
+
getSubscriptionSymbol,
|
|
15
|
+
renewSymbol,
|
|
16
|
+
setHandleSubscriptionSymbol,
|
|
17
|
+
setHandleUpdateSymbol,
|
|
18
|
+
subscribeSymbol,
|
|
19
|
+
unsubscribeSymbol,
|
|
20
|
+
updateSymbol } from "./symbols";
|
|
21
|
+
//#endif
|
package/lib/symbols.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export const updateSymbol = Symbol("update");
|
|
2
|
+
export const getHandleUpdateSymbol = Symbol("getHandleUpdate");
|
|
3
|
+
export const setHandleUpdateSymbol = Symbol("setHandleUpdate");
|
|
4
|
+
export const getAsUpdatesSymbol = Symbol("getAsUpdates");
|
|
5
|
+
export const getAsInitialUpdatedSymbol = Symbol("getAsInitialUpdated");
|
|
6
|
+
export const clearSymbol = Symbol("clear");
|
|
7
|
+
export const subscribeSymbol = Symbol("subscribe");
|
|
8
|
+
export const unsubscribeSymbol = Symbol("unsubscribe");
|
|
9
|
+
export const renewSymbol = Symbol("renew");
|
|
10
|
+
export const getSubscriptionSymbol = Symbol("getSubscription");
|
|
11
|
+
export const getHandleSubscriptionSymbol = Symbol("getHandleSubscription");
|
|
12
|
+
export const setHandleSubscriptionSymbol = Symbol("setHandleSubscription");
|
package/package.json
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "insite-subscriptions-client",
|
|
3
|
+
"version": "1.0.294",
|
|
4
|
+
"description": "inSite subscriptions client side",
|
|
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-client.git"
|
|
15
|
+
},
|
|
16
|
+
"keywords": [
|
|
17
|
+
"insite",
|
|
18
|
+
"publications",
|
|
19
|
+
"subscriptions",
|
|
20
|
+
"client"
|
|
21
|
+
],
|
|
22
|
+
"author": "Eugene Nesvetaev <dev@nesvet.dev> (https://nesvet.dev/)",
|
|
23
|
+
"license": "MIT",
|
|
24
|
+
"dependencies": {
|
|
25
|
+
"@nesvet/n": "^1",
|
|
26
|
+
"eventemitter3": "^5"
|
|
27
|
+
},
|
|
28
|
+
"devDependencies": {
|
|
29
|
+
"@nesvet/eslint-config": "^1"
|
|
30
|
+
},
|
|
31
|
+
"peerDependencies": {
|
|
32
|
+
"insite-subscriptions-server": "*",
|
|
33
|
+
"insite-ws": "*"
|
|
34
|
+
}
|
|
35
|
+
}
|