@rpgjs/client 5.0.0-alpha.8 → 5.0.0-alpha.9
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/RpgClient.d.ts +71 -66
- package/dist/RpgClientEngine.d.ts +39 -0
- package/dist/index13.js +1 -1
- package/dist/index13.js.map +1 -1
- package/dist/index14.js +20 -4
- package/dist/index14.js.map +1 -1
- package/dist/index2.js +70 -1
- package/dist/index2.js.map +1 -1
- package/dist/index21.js +3 -3
- package/dist/index22.js +2 -2
- package/dist/index30.js +1 -1
- package/dist/index31.js +1 -1
- package/dist/index32.js +171 -9
- package/dist/index32.js.map +1 -1
- package/dist/index33.js +492 -4394
- package/dist/index33.js.map +1 -1
- package/dist/index34.js +9 -313
- package/dist/index34.js.map +1 -1
- package/dist/index35.js +4399 -170
- package/dist/index35.js.map +1 -1
- package/dist/index36.js +298 -483
- package/dist/index36.js.map +1 -1
- package/dist/index37.js +1 -1
- package/dist/index38.js +17 -17
- package/dist/index38.js.map +1 -1
- package/dist/index39.js +17 -17
- package/dist/index39.js.map +1 -1
- package/dist/index8.js +18 -0
- package/dist/index8.js.map +1 -1
- package/package.json +2 -2
- package/src/RpgClient.ts +73 -65
- package/src/RpgClientEngine.ts +84 -4
- package/src/components/character.ce +39 -8
- package/src/components/scenes/event-layer.ce +2 -2
- package/src/module.ts +18 -0
- package/tsconfig.json +1 -1
package/dist/index36.js
CHANGED
|
@@ -1,501 +1,316 @@
|
|
|
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
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
super();
|
|
101
|
-
this._url = url;
|
|
102
|
-
this._protocols = protocols;
|
|
103
|
-
this._options = options;
|
|
104
|
-
if (this._options.startClosed) {
|
|
105
|
-
this._shouldReconnect = false;
|
|
106
|
-
}
|
|
107
|
-
if (this._options.debugLogger) {
|
|
108
|
-
this._debugLogger = this._options.debugLogger;
|
|
109
|
-
}
|
|
110
|
-
this._connect();
|
|
111
|
-
}
|
|
112
|
-
static get CONNECTING() {
|
|
113
|
-
return 0;
|
|
114
|
-
}
|
|
115
|
-
static get OPEN() {
|
|
116
|
-
return 1;
|
|
117
|
-
}
|
|
118
|
-
static get CLOSING() {
|
|
119
|
-
return 2;
|
|
120
|
-
}
|
|
121
|
-
static get CLOSED() {
|
|
122
|
-
return 3;
|
|
123
|
-
}
|
|
124
|
-
get CONNECTING() {
|
|
125
|
-
return _ReconnectingWebSocket.CONNECTING;
|
|
126
|
-
}
|
|
127
|
-
get OPEN() {
|
|
128
|
-
return _ReconnectingWebSocket.OPEN;
|
|
129
|
-
}
|
|
130
|
-
get CLOSING() {
|
|
131
|
-
return _ReconnectingWebSocket.CLOSING;
|
|
132
|
-
}
|
|
133
|
-
get CLOSED() {
|
|
134
|
-
return _ReconnectingWebSocket.CLOSED;
|
|
135
|
-
}
|
|
136
|
-
get binaryType() {
|
|
137
|
-
return this._ws ? this._ws.binaryType : this._binaryType;
|
|
138
|
-
}
|
|
139
|
-
set binaryType(value) {
|
|
140
|
-
this._binaryType = value;
|
|
141
|
-
if (this._ws) {
|
|
142
|
-
this._ws.binaryType = value;
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
/**
|
|
146
|
-
* Returns the number or connection retries
|
|
147
|
-
*/
|
|
148
|
-
get retryCount() {
|
|
149
|
-
return Math.max(this._retryCount, 0);
|
|
150
|
-
}
|
|
151
|
-
/**
|
|
152
|
-
* The number of bytes of data that have been queued using calls to send() but not yet
|
|
153
|
-
* transmitted to the network. This value resets to zero once all queued data has been sent.
|
|
154
|
-
* This value does not reset to zero when the connection is closed; if you keep calling send(),
|
|
155
|
-
* this will continue to climb. Read only
|
|
156
|
-
*/
|
|
157
|
-
get bufferedAmount() {
|
|
158
|
-
const bytes = this._messageQueue.reduce((acc, message) => {
|
|
159
|
-
if (typeof message === "string") {
|
|
160
|
-
acc += message.length;
|
|
161
|
-
} else if (message instanceof Blob) {
|
|
162
|
-
acc += message.size;
|
|
163
|
-
} else {
|
|
164
|
-
acc += message.byteLength;
|
|
165
|
-
}
|
|
166
|
-
return acc;
|
|
167
|
-
}, 0);
|
|
168
|
-
return bytes + (this._ws ? this._ws.bufferedAmount : 0);
|
|
169
|
-
}
|
|
170
|
-
/**
|
|
171
|
-
* The extensions selected by the server. This is currently only the empty string or a list of
|
|
172
|
-
* extensions as negotiated by the connection
|
|
173
|
-
*/
|
|
174
|
-
get extensions() {
|
|
175
|
-
return this._ws ? this._ws.extensions : "";
|
|
176
|
-
}
|
|
177
|
-
/**
|
|
178
|
-
* A string indicating the name of the sub-protocol the server selected;
|
|
179
|
-
* this will be one of the strings specified in the protocols parameter when creating the
|
|
180
|
-
* WebSocket object
|
|
181
|
-
*/
|
|
182
|
-
get protocol() {
|
|
183
|
-
return this._ws ? this._ws.protocol : "";
|
|
184
|
-
}
|
|
185
|
-
/**
|
|
186
|
-
* The current state of the connection; this is one of the Ready state constants
|
|
187
|
-
*/
|
|
188
|
-
get readyState() {
|
|
189
|
-
if (this._ws) {
|
|
190
|
-
return this._ws.readyState;
|
|
191
|
-
}
|
|
192
|
-
return this._options.startClosed
|
|
193
|
-
? _ReconnectingWebSocket.CLOSED
|
|
194
|
-
: _ReconnectingWebSocket.CONNECTING;
|
|
195
|
-
}
|
|
196
|
-
/**
|
|
197
|
-
* The URL as resolved by the constructor
|
|
198
|
-
*/
|
|
199
|
-
get url() {
|
|
200
|
-
return this._ws ? this._ws.url : "";
|
|
201
|
-
}
|
|
202
|
-
/**
|
|
203
|
-
* Whether the websocket object is now in reconnectable state
|
|
204
|
-
*/
|
|
205
|
-
get shouldReconnect() {
|
|
206
|
-
return this._shouldReconnect;
|
|
207
|
-
}
|
|
208
|
-
/**
|
|
209
|
-
* An event listener to be called when the WebSocket connection's readyState changes to CLOSED
|
|
210
|
-
*/
|
|
211
|
-
onclose = null;
|
|
212
|
-
/**
|
|
213
|
-
* An event listener to be called when an error occurs
|
|
214
|
-
*/
|
|
215
|
-
onerror = null;
|
|
216
|
-
/**
|
|
217
|
-
* An event listener to be called when a message is received from the server
|
|
218
|
-
*/
|
|
219
|
-
onmessage = null;
|
|
220
|
-
/**
|
|
221
|
-
* An event listener to be called when the WebSocket connection's readyState changes to OPEN;
|
|
222
|
-
* this indicates that the connection is ready to send and receive data
|
|
223
|
-
*/
|
|
224
|
-
onopen = null;
|
|
225
|
-
/**
|
|
226
|
-
* Closes the WebSocket connection or connection attempt, if any. If the connection is already
|
|
227
|
-
* CLOSED, this method does nothing
|
|
228
|
-
*/
|
|
229
|
-
close(code = 1e3, reason) {
|
|
230
|
-
this._closeCalled = true;
|
|
231
|
-
this._shouldReconnect = false;
|
|
232
|
-
this._clearTimeouts();
|
|
233
|
-
if (!this._ws) {
|
|
234
|
-
this._debug("close enqueued: no ws instance");
|
|
235
|
-
return;
|
|
236
|
-
}
|
|
237
|
-
if (this._ws.readyState === this.CLOSED) {
|
|
238
|
-
this._debug("close: already closed");
|
|
239
|
-
return;
|
|
240
|
-
}
|
|
241
|
-
this._ws.close(code, reason);
|
|
1
|
+
import { BehaviorSubject, filter, combineLatest, map, finalize } from 'rxjs';
|
|
2
|
+
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
5
|
+
var ArraySubject = class extends BehaviorSubject {
|
|
6
|
+
static {
|
|
7
|
+
__name(this, "ArraySubject");
|
|
8
|
+
}
|
|
9
|
+
_items = [];
|
|
10
|
+
constructor(items = []) {
|
|
11
|
+
super({
|
|
12
|
+
type: "init",
|
|
13
|
+
items
|
|
14
|
+
});
|
|
15
|
+
this.createProxy(items);
|
|
16
|
+
}
|
|
17
|
+
createProxy(items) {
|
|
18
|
+
this._items = new Proxy(items, {
|
|
19
|
+
get: /* @__PURE__ */ __name((target, prop, receiver) => {
|
|
20
|
+
const origMethod = target[prop];
|
|
21
|
+
if (typeof origMethod === "function") {
|
|
22
|
+
return (...args) => {
|
|
23
|
+
let changeType = "update";
|
|
24
|
+
let index = void 0;
|
|
25
|
+
let isMutateFn = false;
|
|
26
|
+
let itemsToEmit = [];
|
|
27
|
+
let changeSplice = true;
|
|
28
|
+
switch (prop) {
|
|
29
|
+
case "push":
|
|
30
|
+
index = target.length;
|
|
31
|
+
changeType = "add";
|
|
32
|
+
isMutateFn = true;
|
|
33
|
+
break;
|
|
34
|
+
case "pop":
|
|
35
|
+
index = target.length - 1;
|
|
36
|
+
changeType = "remove";
|
|
37
|
+
isMutateFn = true;
|
|
38
|
+
break;
|
|
39
|
+
case "unshift":
|
|
40
|
+
index = 0;
|
|
41
|
+
changeType = "add";
|
|
42
|
+
isMutateFn = true;
|
|
43
|
+
break;
|
|
44
|
+
case "shift":
|
|
45
|
+
index = 0;
|
|
46
|
+
changeType = "remove";
|
|
47
|
+
isMutateFn = true;
|
|
48
|
+
break;
|
|
49
|
+
case "splice":
|
|
50
|
+
index = args[0];
|
|
51
|
+
const deleteCount = args[1];
|
|
52
|
+
const newItems = args.slice(2);
|
|
53
|
+
itemsToEmit = newItems;
|
|
54
|
+
if (deleteCount > 0 && newItems.length === 0) {
|
|
55
|
+
changeType = "remove";
|
|
56
|
+
} else if (deleteCount === 0 && newItems.length > 0) {
|
|
57
|
+
changeType = "add";
|
|
58
|
+
} else if (deleteCount === 0 && newItems.length === 0) {
|
|
59
|
+
changeSplice = false;
|
|
60
|
+
} else {
|
|
61
|
+
changeType = "update";
|
|
62
|
+
}
|
|
63
|
+
isMutateFn = true;
|
|
64
|
+
break;
|
|
65
|
+
}
|
|
66
|
+
const result = origMethod.apply(target, args);
|
|
67
|
+
if (isMutateFn && changeSplice) {
|
|
68
|
+
if (prop === "splice") {
|
|
69
|
+
this.next({
|
|
70
|
+
type: changeType,
|
|
71
|
+
index,
|
|
72
|
+
items: itemsToEmit
|
|
73
|
+
});
|
|
74
|
+
} else {
|
|
75
|
+
this.next({
|
|
76
|
+
type: changeType,
|
|
77
|
+
index,
|
|
78
|
+
items: args
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
return result;
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
return Reflect.get(target, prop, receiver);
|
|
86
|
+
}, "get"),
|
|
87
|
+
set: /* @__PURE__ */ __name((target, prop, value) => {
|
|
88
|
+
const index = !isNaN(Number(prop)) ? Number(prop) : void 0;
|
|
89
|
+
target[prop] = value;
|
|
90
|
+
this.next({
|
|
91
|
+
type: "update",
|
|
92
|
+
index,
|
|
93
|
+
items: [
|
|
94
|
+
value
|
|
95
|
+
]
|
|
96
|
+
});
|
|
97
|
+
return true;
|
|
98
|
+
}, "set")
|
|
99
|
+
});
|
|
242
100
|
}
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
* Resets retry counter;
|
|
246
|
-
*/
|
|
247
|
-
reconnect(code, reason) {
|
|
248
|
-
this._shouldReconnect = true;
|
|
249
|
-
this._closeCalled = false;
|
|
250
|
-
this._retryCount = -1;
|
|
251
|
-
if (!this._ws || this._ws.readyState === this.CLOSED) {
|
|
252
|
-
this._connect();
|
|
253
|
-
} else {
|
|
254
|
-
this._disconnect(code, reason);
|
|
255
|
-
this._connect();
|
|
256
|
-
}
|
|
101
|
+
get items() {
|
|
102
|
+
return this._items;
|
|
257
103
|
}
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
this._ws.send(data);
|
|
265
|
-
} else {
|
|
266
|
-
const { maxEnqueuedMessages = DEFAULT.maxEnqueuedMessages } =
|
|
267
|
-
this._options;
|
|
268
|
-
if (this._messageQueue.length < maxEnqueuedMessages) {
|
|
269
|
-
this._debug("enqueue", data);
|
|
270
|
-
this._messageQueue.push(data);
|
|
271
|
-
}
|
|
272
|
-
}
|
|
104
|
+
set items(newItems) {
|
|
105
|
+
this.createProxy(newItems);
|
|
106
|
+
this.next({
|
|
107
|
+
type: "reset",
|
|
108
|
+
items: newItems
|
|
109
|
+
});
|
|
273
110
|
}
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
111
|
+
};
|
|
112
|
+
var ObjectSubject = class extends BehaviorSubject {
|
|
113
|
+
static {
|
|
114
|
+
__name(this, "ObjectSubject");
|
|
115
|
+
}
|
|
116
|
+
_obj;
|
|
117
|
+
constructor(obj = {}) {
|
|
118
|
+
super({
|
|
119
|
+
type: "init",
|
|
120
|
+
value: obj
|
|
121
|
+
});
|
|
122
|
+
this.createProxy(obj);
|
|
123
|
+
}
|
|
124
|
+
createProxy(obj) {
|
|
125
|
+
this._obj = new Proxy(obj, {
|
|
126
|
+
get: /* @__PURE__ */ __name((target, prop, receiver) => {
|
|
127
|
+
return Reflect.get(target, prop, receiver);
|
|
128
|
+
}, "get"),
|
|
129
|
+
set: /* @__PURE__ */ __name((target, prop, value, receiver) => {
|
|
130
|
+
const key = prop;
|
|
131
|
+
const changeType = key in target ? "update" : "add";
|
|
132
|
+
target[key] = value;
|
|
133
|
+
this.next({
|
|
134
|
+
type: changeType,
|
|
135
|
+
key,
|
|
136
|
+
value
|
|
137
|
+
});
|
|
138
|
+
return true;
|
|
139
|
+
}, "set"),
|
|
140
|
+
deleteProperty: /* @__PURE__ */ __name((target, prop) => {
|
|
141
|
+
const key = prop;
|
|
142
|
+
if (key in target) {
|
|
143
|
+
const value = target[key];
|
|
144
|
+
delete target[key];
|
|
145
|
+
this.next({
|
|
146
|
+
type: "remove",
|
|
147
|
+
key,
|
|
148
|
+
value
|
|
149
|
+
});
|
|
150
|
+
return true;
|
|
151
|
+
}
|
|
152
|
+
return false;
|
|
153
|
+
}, "deleteProperty")
|
|
154
|
+
});
|
|
278
155
|
}
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
reconnectionDelayGrowFactor = DEFAULT.reconnectionDelayGrowFactor,
|
|
282
|
-
minReconnectionDelay = DEFAULT.minReconnectionDelay,
|
|
283
|
-
maxReconnectionDelay = DEFAULT.maxReconnectionDelay
|
|
284
|
-
} = this._options;
|
|
285
|
-
let delay = 0;
|
|
286
|
-
if (this._retryCount > 0) {
|
|
287
|
-
delay =
|
|
288
|
-
minReconnectionDelay *
|
|
289
|
-
reconnectionDelayGrowFactor ** (this._retryCount - 1);
|
|
290
|
-
if (delay > maxReconnectionDelay) {
|
|
291
|
-
delay = maxReconnectionDelay;
|
|
292
|
-
}
|
|
293
|
-
}
|
|
294
|
-
this._debug("next delay", delay);
|
|
295
|
-
return delay;
|
|
156
|
+
get obj() {
|
|
157
|
+
return this._obj;
|
|
296
158
|
}
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
159
|
+
set obj(newObj) {
|
|
160
|
+
this.createProxy(newObj);
|
|
161
|
+
this.next({
|
|
162
|
+
type: "reset",
|
|
163
|
+
value: newObj
|
|
300
164
|
});
|
|
301
165
|
}
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
const protocols = protocolsProvider();
|
|
312
|
-
if (!protocols) return Promise.resolve(null);
|
|
313
|
-
if (typeof protocols === "string" || Array.isArray(protocols)) {
|
|
314
|
-
return Promise.resolve(protocols);
|
|
315
|
-
}
|
|
316
|
-
if (protocols.then) {
|
|
317
|
-
return protocols;
|
|
318
|
-
}
|
|
319
|
-
}
|
|
320
|
-
throw Error("Invalid protocols");
|
|
321
|
-
}
|
|
322
|
-
_getNextUrl(urlProvider) {
|
|
323
|
-
if (typeof urlProvider === "string") {
|
|
324
|
-
return Promise.resolve(urlProvider);
|
|
325
|
-
}
|
|
326
|
-
if (typeof urlProvider === "function") {
|
|
327
|
-
const url = urlProvider();
|
|
328
|
-
if (typeof url === "string") {
|
|
329
|
-
return Promise.resolve(url);
|
|
330
|
-
}
|
|
331
|
-
if (url.then) {
|
|
332
|
-
return url;
|
|
333
|
-
}
|
|
166
|
+
};
|
|
167
|
+
var getGlobalReactiveStore = /* @__PURE__ */ __name(() => {
|
|
168
|
+
const globalKey = "__REACTIVE_STORE__";
|
|
169
|
+
if (typeof globalThis !== "undefined") {
|
|
170
|
+
if (!globalThis[globalKey]) {
|
|
171
|
+
globalThis[globalKey] = {
|
|
172
|
+
currentDependencyTracker: null,
|
|
173
|
+
currentSubscriptionsTracker: null
|
|
174
|
+
};
|
|
334
175
|
}
|
|
335
|
-
|
|
336
|
-
}
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
176
|
+
return globalThis[globalKey];
|
|
177
|
+
}
|
|
178
|
+
let globalObj;
|
|
179
|
+
if (typeof window !== "undefined") {
|
|
180
|
+
globalObj = window;
|
|
181
|
+
} else if (typeof process !== "undefined" && process.versions && process.versions.node) {
|
|
182
|
+
globalObj = Function("return this")();
|
|
183
|
+
} else if (typeof self !== "undefined") {
|
|
184
|
+
globalObj = self;
|
|
185
|
+
} else {
|
|
186
|
+
console.warn("Unable to find global object, using local instance");
|
|
187
|
+
return {
|
|
188
|
+
currentDependencyTracker: null,
|
|
189
|
+
currentSubscriptionsTracker: null
|
|
190
|
+
};
|
|
191
|
+
}
|
|
192
|
+
if (!globalObj[globalKey]) {
|
|
193
|
+
globalObj[globalKey] = {
|
|
194
|
+
currentDependencyTracker: null,
|
|
195
|
+
currentSubscriptionsTracker: null
|
|
196
|
+
};
|
|
197
|
+
}
|
|
198
|
+
return globalObj[globalKey];
|
|
199
|
+
}, "getGlobalReactiveStore");
|
|
200
|
+
var reactiveStore = getGlobalReactiveStore();
|
|
201
|
+
var trackDependency = /* @__PURE__ */ __name((signal2) => {
|
|
202
|
+
if (reactiveStore.currentDependencyTracker) {
|
|
203
|
+
reactiveStore.currentDependencyTracker(signal2);
|
|
204
|
+
}
|
|
205
|
+
}, "trackDependency");
|
|
206
|
+
function signal(defaultValue) {
|
|
207
|
+
let subject;
|
|
208
|
+
if (Array.isArray(defaultValue)) {
|
|
209
|
+
subject = new ArraySubject(defaultValue);
|
|
210
|
+
} else if (typeof defaultValue === "object" && defaultValue !== null) {
|
|
211
|
+
subject = new ObjectSubject(defaultValue);
|
|
212
|
+
} else {
|
|
213
|
+
subject = new BehaviorSubject(defaultValue);
|
|
214
|
+
}
|
|
215
|
+
const getValue = /* @__PURE__ */ __name(() => {
|
|
216
|
+
if (subject instanceof ArraySubject) {
|
|
217
|
+
return subject.items;
|
|
218
|
+
} else if (subject instanceof ObjectSubject) {
|
|
219
|
+
return subject.obj;
|
|
340
220
|
}
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
221
|
+
return subject.value;
|
|
222
|
+
}, "getValue");
|
|
223
|
+
const fn = /* @__PURE__ */ __name(function() {
|
|
224
|
+
trackDependency(fn);
|
|
225
|
+
return getValue();
|
|
226
|
+
}, "fn");
|
|
227
|
+
fn.set = (value) => {
|
|
228
|
+
if (subject instanceof ArraySubject) {
|
|
229
|
+
subject.items = value;
|
|
230
|
+
} else if (subject instanceof ObjectSubject) {
|
|
231
|
+
subject.obj = value;
|
|
232
|
+
} else {
|
|
233
|
+
subject.next(value);
|
|
349
234
|
}
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
if (this._closeCalled) {
|
|
362
|
-
this._connectLock = false;
|
|
363
|
-
return;
|
|
364
|
-
}
|
|
365
|
-
if (
|
|
366
|
-
!this._options.WebSocket &&
|
|
367
|
-
typeof WebSocket === "undefined" &&
|
|
368
|
-
!didWarnAboutMissingWebSocket
|
|
369
|
-
) {
|
|
370
|
-
console.error(`\u203C\uFE0F No WebSocket implementation available. You should define options.WebSocket.
|
|
371
|
-
|
|
372
|
-
For example, if you're using node.js, run \`npm install ws\`, and then in your code:
|
|
373
|
-
|
|
374
|
-
import PartySocket from 'partysocket';
|
|
375
|
-
import WS from 'ws';
|
|
376
|
-
|
|
377
|
-
const partysocket = new PartySocket({
|
|
378
|
-
host: "127.0.0.1:1999",
|
|
379
|
-
room: "test-room",
|
|
380
|
-
WebSocket: WS
|
|
381
|
-
});
|
|
382
|
-
|
|
383
|
-
`);
|
|
384
|
-
didWarnAboutMissingWebSocket = true;
|
|
385
|
-
}
|
|
386
|
-
const WS = this._options.WebSocket || WebSocket;
|
|
387
|
-
this._debug("connect", { url, protocols });
|
|
388
|
-
this._ws = protocols ? new WS(url, protocols) : new WS(url);
|
|
389
|
-
this._ws.binaryType = this._binaryType;
|
|
390
|
-
this._connectLock = false;
|
|
391
|
-
this._addListeners();
|
|
392
|
-
this._connectTimeout = setTimeout(
|
|
393
|
-
() => this._handleTimeout(),
|
|
394
|
-
connectionTimeout
|
|
395
|
-
);
|
|
396
|
-
})
|
|
397
|
-
.catch((err) => {
|
|
398
|
-
this._connectLock = false;
|
|
399
|
-
this._handleError(new Events.ErrorEvent(Error(err.message), this));
|
|
235
|
+
};
|
|
236
|
+
fn._isFrozen = false;
|
|
237
|
+
fn.freeze = () => {
|
|
238
|
+
fn._isFrozen = true;
|
|
239
|
+
};
|
|
240
|
+
fn.unfreeze = () => {
|
|
241
|
+
fn._isFrozen = false;
|
|
242
|
+
if (subject instanceof ArraySubject) {
|
|
243
|
+
subject.next({
|
|
244
|
+
type: "init",
|
|
245
|
+
items: subject.items
|
|
400
246
|
});
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
if (!this._ws) {
|
|
409
|
-
return;
|
|
410
|
-
}
|
|
411
|
-
this._removeListeners();
|
|
412
|
-
try {
|
|
413
|
-
if (this._ws.readyState === this.OPEN) {
|
|
414
|
-
this._ws.close(code, reason);
|
|
415
|
-
}
|
|
416
|
-
this._handleClose(new Events.CloseEvent(code, reason, this));
|
|
417
|
-
} catch (error) {}
|
|
418
|
-
}
|
|
419
|
-
_acceptOpen() {
|
|
420
|
-
this._debug("accept open");
|
|
421
|
-
this._retryCount = 0;
|
|
422
|
-
}
|
|
423
|
-
_handleOpen = (event) => {
|
|
424
|
-
this._debug("open event");
|
|
425
|
-
const { minUptime = DEFAULT.minUptime } = this._options;
|
|
426
|
-
clearTimeout(this._connectTimeout);
|
|
427
|
-
this._uptimeTimeout = setTimeout(() => this._acceptOpen(), minUptime);
|
|
428
|
-
assert(this._ws, "WebSocket is not defined");
|
|
429
|
-
this._ws.binaryType = this._binaryType;
|
|
430
|
-
this._messageQueue.forEach((message) => {
|
|
431
|
-
var _a2;
|
|
432
|
-
return (_a2 = this._ws) == null ? void 0 : _a2.send(message);
|
|
433
|
-
});
|
|
434
|
-
this._messageQueue = [];
|
|
435
|
-
if (this.onopen) {
|
|
436
|
-
this.onopen(event);
|
|
247
|
+
} else if (subject instanceof ObjectSubject) {
|
|
248
|
+
subject.next({
|
|
249
|
+
type: "init",
|
|
250
|
+
value: subject.obj
|
|
251
|
+
});
|
|
252
|
+
} else {
|
|
253
|
+
subject.next(subject.value);
|
|
437
254
|
}
|
|
438
|
-
this.dispatchEvent(cloneEvent(event));
|
|
439
255
|
};
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
this.onmessage(event);
|
|
444
|
-
}
|
|
445
|
-
this.dispatchEvent(cloneEvent(event));
|
|
256
|
+
fn.mutate = (mutateFn) => {
|
|
257
|
+
const value = getValue();
|
|
258
|
+
mutateFn(value);
|
|
446
259
|
};
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
if (this.onerror) {
|
|
451
|
-
this.onerror(event);
|
|
452
|
-
}
|
|
453
|
-
this._debug("exec error listeners");
|
|
454
|
-
this.dispatchEvent(cloneEvent(event));
|
|
455
|
-
this._connect();
|
|
260
|
+
fn.update = (updateFn) => {
|
|
261
|
+
const updatedValue = updateFn(getValue());
|
|
262
|
+
fn.set(updatedValue);
|
|
456
263
|
};
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
264
|
+
fn.observable = subject.asObservable().pipe(filter(() => !fn._isFrozen));
|
|
265
|
+
fn._subject = subject;
|
|
266
|
+
return fn;
|
|
267
|
+
}
|
|
268
|
+
__name(signal, "signal");
|
|
269
|
+
function isSignal(value) {
|
|
270
|
+
return !!(value && value.observable);
|
|
271
|
+
}
|
|
272
|
+
__name(isSignal, "isSignal");
|
|
273
|
+
function isComputed(value) {
|
|
274
|
+
return isSignal(value) && !!value.dependencies;
|
|
275
|
+
}
|
|
276
|
+
__name(isComputed, "isComputed");
|
|
277
|
+
function computed(computeFunction, disposableFn) {
|
|
278
|
+
const dependencies = /* @__PURE__ */ new Set();
|
|
279
|
+
let init = true;
|
|
280
|
+
let lastComputedValue;
|
|
281
|
+
const previousTracker = reactiveStore.currentDependencyTracker;
|
|
282
|
+
reactiveStore.currentDependencyTracker = (signal2) => {
|
|
283
|
+
dependencies.add(signal2);
|
|
467
284
|
};
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
* License MIT
|
|
498
|
-
*/
|
|
285
|
+
lastComputedValue = computeFunction();
|
|
286
|
+
if (computeFunction["isEffect"]) {
|
|
287
|
+
disposableFn = lastComputedValue;
|
|
288
|
+
}
|
|
289
|
+
reactiveStore.currentDependencyTracker = previousTracker;
|
|
290
|
+
const computedObservable = combineLatest([
|
|
291
|
+
...dependencies
|
|
292
|
+
].map((signal2) => signal2.observable)).pipe(filter(() => !init), map(() => computeFunction()), finalize(() => disposableFn?.()));
|
|
293
|
+
const fn = /* @__PURE__ */ __name(function() {
|
|
294
|
+
trackDependency(fn);
|
|
295
|
+
return lastComputedValue;
|
|
296
|
+
}, "fn");
|
|
297
|
+
fn.observable = computedObservable;
|
|
298
|
+
fn.subscription = computedObservable.subscribe((value) => {
|
|
299
|
+
lastComputedValue = value;
|
|
300
|
+
});
|
|
301
|
+
fn.dependencies = dependencies;
|
|
302
|
+
reactiveStore.currentSubscriptionsTracker?.(fn.subscription);
|
|
303
|
+
init = false;
|
|
304
|
+
return fn;
|
|
305
|
+
}
|
|
306
|
+
__name(computed, "computed");
|
|
307
|
+
|
|
308
|
+
// src/effect.ts
|
|
309
|
+
function effect(fn) {
|
|
310
|
+
fn["isEffect"] = true;
|
|
311
|
+
return computed(fn);
|
|
312
|
+
}
|
|
313
|
+
__name(effect, "effect");
|
|
499
314
|
|
|
500
|
-
export {
|
|
315
|
+
export { ArraySubject, ObjectSubject, computed, effect, isComputed, isSignal, signal };
|
|
501
316
|
//# sourceMappingURL=index36.js.map
|