@liveblocks/client 0.16.4 → 0.16.7
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/index.js +815 -1540
- package/index.mjs +778 -1295
- package/internal.d.ts +37 -5
- package/internal.js +152 -337
- package/internal.mjs +127 -299
- package/package.json +8 -7
- package/shared.d.ts +15 -3
- package/shared.js +1276 -2380
- package/shared.mjs +1183 -1887
package/internal.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { d as JsonObject, J as Json, e as Lson, A as AbstractCrdt, f as LsonObject, L as LiveObject, S as StorageUpdate } from './shared';
|
|
2
2
|
export { g as Resolve, h as RoomInitializers } from './shared';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Messages that can be sent from the server to the client.
|
|
6
6
|
*/
|
|
7
|
-
declare type ServerMessage = UpdatePresenceMessage | UserJoinMessage | UserLeftMessage | EventMessage | RoomStateMessage | InitialDocumentStateMessage | UpdateStorageMessage;
|
|
7
|
+
declare type ServerMessage<TPresence extends JsonObject> = UpdatePresenceMessage<TPresence> | UserJoinMessage | UserLeftMessage | EventMessage | RoomStateMessage | InitialDocumentStateMessage | UpdateStorageMessage;
|
|
8
8
|
declare enum ServerMessageType {
|
|
9
9
|
UpdatePresence = 100,
|
|
10
10
|
UserJoined = 101,
|
|
@@ -39,7 +39,7 @@ declare type RoomStateMessage = {
|
|
|
39
39
|
* those cases, the `targetActor` field indicates the newly connected client,
|
|
40
40
|
* so all other existing clients can ignore this broadcasted message.
|
|
41
41
|
*/
|
|
42
|
-
declare type UpdatePresenceMessage = {
|
|
42
|
+
declare type UpdatePresenceMessage<TPresence extends JsonObject> = {
|
|
43
43
|
type: ServerMessageType.UpdatePresence;
|
|
44
44
|
/**
|
|
45
45
|
* The User whose Presence has changed.
|
|
@@ -50,7 +50,7 @@ declare type UpdatePresenceMessage = {
|
|
|
50
50
|
* this will be the full Presence, otherwise it only contain the fields that
|
|
51
51
|
* have changed since the last broadcast.
|
|
52
52
|
*/
|
|
53
|
-
data:
|
|
53
|
+
data: TPresence;
|
|
54
54
|
/**
|
|
55
55
|
* If this message was sent in response to a newly joined user, this field
|
|
56
56
|
* indicates which client this message is for. Other existing clients may
|
|
@@ -229,7 +229,22 @@ declare type DeleteObjectKeyOp = {
|
|
|
229
229
|
type: OpType.DeleteObjectKey;
|
|
230
230
|
key: string;
|
|
231
231
|
};
|
|
232
|
+
declare enum WebsocketCloseCodes {
|
|
233
|
+
CLOSE_ABNORMAL = 1006,
|
|
234
|
+
INVALID_MESSAGE_FORMAT = 4000,
|
|
235
|
+
NOT_ALLOWED = 4001,
|
|
236
|
+
MAX_NUMBER_OF_MESSAGES_PER_SECONDS = 4002,
|
|
237
|
+
MAX_NUMBER_OF_CONCURRENT_CONNECTIONS = 4003,
|
|
238
|
+
MAX_NUMBER_OF_MESSAGES_PER_DAY_PER_APP = 4004,
|
|
239
|
+
MAX_NUMBER_OF_CONCURRENT_CONNECTIONS_PER_ROOM = 4005,
|
|
240
|
+
CLOSE_WITHOUT_RETRY = 4999
|
|
241
|
+
}
|
|
232
242
|
|
|
243
|
+
/**
|
|
244
|
+
* Tools to help with the controlled deprecation of public APIs.
|
|
245
|
+
*
|
|
246
|
+
* First warn, then error, then remove eventually.
|
|
247
|
+
*/
|
|
233
248
|
/**
|
|
234
249
|
* Displays a deprecation warning in the dev console. Only in dev mode, and
|
|
235
250
|
* only once per message/key. In production, this is a no-op.
|
|
@@ -241,9 +256,26 @@ declare function deprecate(message: string, key?: string): void;
|
|
|
241
256
|
* only once per message/key. In production, this is a no-op.
|
|
242
257
|
*/
|
|
243
258
|
declare function deprecateIf(condition: unknown, message: string, key?: string): void;
|
|
259
|
+
/**
|
|
260
|
+
* Throws a deprecation error in the dev console.
|
|
261
|
+
*
|
|
262
|
+
* Only triggers in dev mode. In production, this is a no-op.
|
|
263
|
+
*/
|
|
264
|
+
declare function throwUsageError(message: string): void;
|
|
265
|
+
/**
|
|
266
|
+
* Conditionally throws a usage error in the dev console if the first argument
|
|
267
|
+
* is truthy. Use this to "escalate" usage patterns that in previous versions
|
|
268
|
+
* we already warned about with deprecation warnings.
|
|
269
|
+
*
|
|
270
|
+
* Only has effect in dev mode. In production, this is a no-op.
|
|
271
|
+
*/
|
|
272
|
+
declare function errorIf(condition: unknown, message: string): void;
|
|
244
273
|
|
|
245
274
|
declare function lsonToJson(value: Lson | AbstractCrdt): Json;
|
|
246
275
|
declare function patchLiveObjectKey<O extends LsonObject>(liveObject: LiveObject<O>, key: keyof O, prev: unknown, next: unknown): void;
|
|
247
276
|
declare function patchImmutableObject<T>(state: T, updates: StorageUpdate[]): T;
|
|
248
277
|
|
|
249
|
-
|
|
278
|
+
declare function makePosition(before?: string, after?: string): string;
|
|
279
|
+
declare function comparePosition(posA: string, posB: string): number;
|
|
280
|
+
|
|
281
|
+
export { ClientMessageType, CrdtType, CreateListOp, CreateMapOp, CreateObjectOp, CreateRegisterOp, DeleteCrdtOp, DeleteObjectKeyOp, Op, OpType, RoomStateMessage, SerializedCrdt, SerializedCrdtWithId, SerializedList, SerializedMap, SerializedObject, SerializedRegister, ServerMessage, ServerMessageType, WebsocketCloseCodes, comparePosition, deprecate, deprecateIf, errorIf, lsonToJson, makePosition, patchImmutableObject, patchLiveObjectKey, throwUsageError };
|
package/internal.js
CHANGED
|
@@ -1,367 +1,182 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
2
|
|
|
3
|
-
Object.defineProperty(exports,
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: !0
|
|
5
|
+
});
|
|
4
6
|
|
|
5
|
-
var LiveObject = require(
|
|
7
|
+
var LiveObject = require("./shared.js");
|
|
6
8
|
|
|
7
9
|
function lsonObjectToJson(obj) {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
result[_key] = lsonToJson(val);
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
return result;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
function liveObjectToJson(liveObject) {
|
|
22
|
-
return lsonObjectToJson(liveObject.toObject());
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
function liveMapToJson(map) {
|
|
26
|
-
var result = {};
|
|
27
|
-
|
|
28
|
-
for (var _iterator = LiveObject._createForOfIteratorHelperLoose(map.entries()), _step; !(_step = _iterator()).done;) {
|
|
29
|
-
var _step$value = _step.value,
|
|
30
|
-
_key2 = _step$value[0],
|
|
31
|
-
value = _step$value[1];
|
|
32
|
-
result[_key2] = lsonToJson(value);
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
return result;
|
|
10
|
+
var result = {};
|
|
11
|
+
for (var _key in obj) {
|
|
12
|
+
var val = obj[_key];
|
|
13
|
+
void 0 !== val && (result[_key] = lsonToJson(val));
|
|
14
|
+
}
|
|
15
|
+
return result;
|
|
36
16
|
}
|
|
37
17
|
|
|
38
18
|
function lsonListToJson(value) {
|
|
39
|
-
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
function liveListToJson(value) {
|
|
43
|
-
return lsonListToJson(value.toArray());
|
|
19
|
+
return value.map(lsonToJson);
|
|
44
20
|
}
|
|
45
21
|
|
|
46
22
|
function lsonToJson(value) {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
} else if (value instanceof LiveObject.AbstractCrdt) {
|
|
56
|
-
throw new Error("Unhandled subclass of AbstractCrdt encountered");
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
if (Array.isArray(value)) {
|
|
60
|
-
return lsonListToJson(value);
|
|
61
|
-
} else if (isPlainObject(value)) {
|
|
62
|
-
return lsonObjectToJson(value);
|
|
23
|
+
if (value instanceof LiveObject.LiveObject) return lsonObjectToJson(value.toObject());
|
|
24
|
+
if (value instanceof LiveObject.LiveList) return function(value) {
|
|
25
|
+
return lsonListToJson(value.toArray());
|
|
26
|
+
}(value);
|
|
27
|
+
if (value instanceof LiveObject.LiveMap) return function(map) {
|
|
28
|
+
for (var _step, result = {}, _iterator = LiveObject._createForOfIteratorHelperLoose(map.entries()); !(_step = _iterator()).done; ) {
|
|
29
|
+
var _step$value = _step.value, _key2 = _step$value[0], value = _step$value[1];
|
|
30
|
+
result[_key2] = lsonToJson(value);
|
|
63
31
|
}
|
|
64
|
-
|
|
65
|
-
|
|
32
|
+
return result;
|
|
33
|
+
}(value);
|
|
34
|
+
if (value instanceof LiveObject.LiveRegister) return value.data;
|
|
35
|
+
if (value instanceof LiveObject.AbstractCrdt) throw new Error("Unhandled subclass of AbstractCrdt encountered");
|
|
36
|
+
return Array.isArray(value) ? lsonListToJson(value) : isPlainObject(value) ? lsonObjectToJson(value) : value;
|
|
66
37
|
}
|
|
67
38
|
|
|
68
39
|
function isPlainObject(obj) {
|
|
69
|
-
|
|
40
|
+
return null !== obj && "[object Object]" === Object.prototype.toString.call(obj);
|
|
70
41
|
}
|
|
71
42
|
|
|
72
43
|
function anyToCrdt(obj) {
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
if (isPlainObject(obj)) {
|
|
82
|
-
var init = {};
|
|
83
|
-
|
|
84
|
-
for (var _key3 in obj) {
|
|
85
|
-
init[_key3] = anyToCrdt(obj[_key3]);
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
return new LiveObject.LiveObject(init);
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
return obj;
|
|
44
|
+
if (null == obj) return obj;
|
|
45
|
+
if (Array.isArray(obj)) return new LiveObject.LiveList(obj.map(anyToCrdt));
|
|
46
|
+
if (isPlainObject(obj)) {
|
|
47
|
+
var init = {};
|
|
48
|
+
for (var _key3 in obj) init[_key3] = anyToCrdt(obj[_key3]);
|
|
49
|
+
return new LiveObject.LiveObject(init);
|
|
50
|
+
}
|
|
51
|
+
return obj;
|
|
92
52
|
}
|
|
93
53
|
|
|
94
|
-
function patchLiveList(liveList, prev, next) {
|
|
95
|
-
var i = 0;
|
|
96
|
-
var prevEnd = prev.length - 1;
|
|
97
|
-
var nextEnd = next.length - 1;
|
|
98
|
-
var prevNode = prev[0];
|
|
99
|
-
var nextNode = next[0];
|
|
100
|
-
|
|
101
|
-
outer: {
|
|
102
|
-
while (prevNode === nextNode) {
|
|
103
|
-
++i;
|
|
104
|
-
|
|
105
|
-
if (i > prevEnd || i > nextEnd) {
|
|
106
|
-
break outer;
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
prevNode = prev[i];
|
|
110
|
-
nextNode = next[i];
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
prevNode = prev[prevEnd];
|
|
114
|
-
nextNode = next[nextEnd];
|
|
115
|
-
|
|
116
|
-
while (prevNode === nextNode) {
|
|
117
|
-
prevEnd--;
|
|
118
|
-
nextEnd--;
|
|
119
|
-
|
|
120
|
-
if (i > prevEnd || i > nextEnd) {
|
|
121
|
-
break outer;
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
prevNode = prev[prevEnd];
|
|
125
|
-
nextNode = next[nextEnd];
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
if (i > prevEnd) {
|
|
130
|
-
if (i <= nextEnd) {
|
|
131
|
-
while (i <= nextEnd) {
|
|
132
|
-
liveList.insert(anyToCrdt(next[i]), i);
|
|
133
|
-
i++;
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
} else if (i > nextEnd) {
|
|
137
|
-
var localI = i;
|
|
138
|
-
|
|
139
|
-
while (localI <= prevEnd) {
|
|
140
|
-
liveList.delete(i);
|
|
141
|
-
localI++;
|
|
142
|
-
}
|
|
143
|
-
} else {
|
|
144
|
-
while (i <= prevEnd && i <= nextEnd) {
|
|
145
|
-
prevNode = prev[i];
|
|
146
|
-
nextNode = next[i];
|
|
147
|
-
var liveListNode = liveList.get(i);
|
|
148
|
-
|
|
149
|
-
if (liveListNode instanceof LiveObject.LiveObject && isPlainObject(prevNode) && isPlainObject(nextNode)) {
|
|
150
|
-
patchLiveObject(liveListNode, prevNode, nextNode);
|
|
151
|
-
} else {
|
|
152
|
-
liveList.set(i, anyToCrdt(nextNode));
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
i++;
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
while (i <= nextEnd) {
|
|
159
|
-
liveList.insert(anyToCrdt(next[i]), i);
|
|
160
|
-
i++;
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
var _localI = i;
|
|
164
|
-
|
|
165
|
-
while (_localI <= prevEnd) {
|
|
166
|
-
liveList.delete(i);
|
|
167
|
-
_localI++;
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
54
|
function patchLiveObjectKey(liveObject, key, prev, next) {
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
55
|
+
if ("production" !== process.env.NODE_ENV) {
|
|
56
|
+
var nonSerializableValue = LiveObject.findNonSerializableValue(next);
|
|
57
|
+
if (nonSerializableValue) return void console.error("New state path: '" + nonSerializableValue.path + "' value: '" + nonSerializableValue.value + "' is not serializable.\nOnly serializable value can be synced with Liveblocks.");
|
|
58
|
+
}
|
|
59
|
+
var value = liveObject.get(key);
|
|
60
|
+
if (void 0 === next) liveObject.delete(key); else if (void 0 === value) liveObject.set(key, anyToCrdt(next)); else {
|
|
61
|
+
if (prev === next) return;
|
|
62
|
+
value instanceof LiveObject.LiveList && Array.isArray(prev) && Array.isArray(next) ? function(liveList, prev, next) {
|
|
63
|
+
var i = 0, prevEnd = prev.length - 1, nextEnd = next.length - 1, prevNode = prev[0], nextNode = next[0];
|
|
64
|
+
outer: {
|
|
65
|
+
for (;prevNode === nextNode; ) {
|
|
66
|
+
if (++i > prevEnd || i > nextEnd) break outer;
|
|
67
|
+
prevNode = prev[i], nextNode = next[i];
|
|
178
68
|
}
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
if (next === undefined) {
|
|
184
|
-
liveObject.delete(key);
|
|
185
|
-
} else if (value === undefined) {
|
|
186
|
-
liveObject.set(key, anyToCrdt(next));
|
|
187
|
-
} else if (prev === next) {
|
|
188
|
-
return;
|
|
189
|
-
} else if (value instanceof LiveObject.LiveList && Array.isArray(prev) && Array.isArray(next)) {
|
|
190
|
-
patchLiveList(value, prev, next);
|
|
191
|
-
} else if (value instanceof LiveObject.LiveObject && isPlainObject(prev) && isPlainObject(next)) {
|
|
192
|
-
patchLiveObject(value, prev, next);
|
|
193
|
-
} else {
|
|
194
|
-
liveObject.set(key, anyToCrdt(next));
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
function patchLiveObject(root, prev, next) {
|
|
198
|
-
var updates = {};
|
|
199
|
-
|
|
200
|
-
for (var _key4 in next) {
|
|
201
|
-
patchLiveObjectKey(root, _key4, prev[_key4], next[_key4]);
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
for (var _key5 in prev) {
|
|
205
|
-
if (next[_key5] === undefined) {
|
|
206
|
-
root.delete(_key5);
|
|
69
|
+
for (prevNode = prev[prevEnd], nextNode = next[nextEnd]; prevNode === nextNode; ) {
|
|
70
|
+
if (nextEnd--, i > --prevEnd || i > nextEnd) break outer;
|
|
71
|
+
prevNode = prev[prevEnd], nextNode = next[nextEnd];
|
|
207
72
|
}
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
if (node._parent instanceof LiveObject.LiveList) {
|
|
220
|
-
path.push(node._parent._indexOfPosition(node._parentKey));
|
|
221
|
-
} else {
|
|
222
|
-
path.push(node._parentKey);
|
|
73
|
+
}
|
|
74
|
+
if (i > prevEnd) {
|
|
75
|
+
if (i <= nextEnd) for (;i <= nextEnd; ) liveList.insert(anyToCrdt(next[i]), i),
|
|
76
|
+
i++;
|
|
77
|
+
} else if (i > nextEnd) for (var localI = i; localI <= prevEnd; ) liveList.delete(i),
|
|
78
|
+
localI++; else {
|
|
79
|
+
for (;i <= prevEnd && i <= nextEnd; ) {
|
|
80
|
+
prevNode = prev[i], nextNode = next[i];
|
|
81
|
+
var liveListNode = liveList.get(i);
|
|
82
|
+
liveListNode instanceof LiveObject.LiveObject && isPlainObject(prevNode) && isPlainObject(nextNode) ? patchLiveObject(liveListNode, prevNode, nextNode) : liveList.set(i, anyToCrdt(nextNode)),
|
|
83
|
+
i++;
|
|
223
84
|
}
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
function patchImmutableObject(state, updates) {
|
|
232
|
-
return updates.reduce(function (state, update) {
|
|
233
|
-
return patchImmutableObjectWithUpdate(state, update);
|
|
234
|
-
}, state);
|
|
85
|
+
for (;i <= nextEnd; ) liveList.insert(anyToCrdt(next[i]), i), i++;
|
|
86
|
+
for (var _localI = i; _localI <= prevEnd; ) liveList.delete(i), _localI++;
|
|
87
|
+
}
|
|
88
|
+
}(value, prev, next) : value instanceof LiveObject.LiveObject && isPlainObject(prev) && isPlainObject(next) ? patchLiveObject(value, prev, next) : liveObject.set(key, anyToCrdt(next));
|
|
89
|
+
}
|
|
235
90
|
}
|
|
236
91
|
|
|
237
|
-
function
|
|
238
|
-
|
|
239
|
-
|
|
92
|
+
function patchLiveObject(root, prev, next) {
|
|
93
|
+
var updates = {};
|
|
94
|
+
for (var _key4 in next) patchLiveObjectKey(root, _key4, prev[_key4], next[_key4]);
|
|
95
|
+
for (var _key5 in prev) void 0 === next[_key5] && root.delete(_key5);
|
|
96
|
+
Object.keys(updates).length > 0 && root.update(updates);
|
|
240
97
|
}
|
|
241
98
|
|
|
242
99
|
function patchImmutableNode(state, path, update) {
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
if (listUpdate.type === "set") {
|
|
286
|
-
_newState = _newState.map(function (item, index) {
|
|
287
|
-
return index === listUpdate.index ? listUpdate.item : item;
|
|
288
|
-
});
|
|
289
|
-
} else if (listUpdate.type === "insert") {
|
|
290
|
-
if (listUpdate.index === _newState.length) {
|
|
291
|
-
_newState.push(lsonToJson(listUpdate.item));
|
|
292
|
-
} else {
|
|
293
|
-
_newState = [].concat(_newState.slice(0, listUpdate.index), [lsonToJson(listUpdate.item)], _newState.slice(listUpdate.index));
|
|
294
|
-
}
|
|
295
|
-
} else if (listUpdate.type === "delete") {
|
|
296
|
-
_newState.splice(listUpdate.index, 1);
|
|
297
|
-
} else if (listUpdate.type === "move") {
|
|
298
|
-
if (listUpdate.previousIndex > listUpdate.index) {
|
|
299
|
-
_newState = [].concat(_newState.slice(0, listUpdate.index), [lsonToJson(listUpdate.item)], _newState.slice(listUpdate.index, listUpdate.previousIndex), _newState.slice(listUpdate.previousIndex + 1));
|
|
300
|
-
} else {
|
|
301
|
-
_newState = [].concat(_newState.slice(0, listUpdate.previousIndex), _newState.slice(listUpdate.previousIndex + 1, listUpdate.index + 1), [lsonToJson(listUpdate.item)], _newState.slice(listUpdate.index + 1));
|
|
302
|
-
}
|
|
303
|
-
}
|
|
304
|
-
};
|
|
305
|
-
|
|
306
|
-
for (var _iterator2 = LiveObject._createForOfIteratorHelperLoose(update.updates), _step2; !(_step2 = _iterator2()).done;) {
|
|
307
|
-
_loop();
|
|
308
|
-
}
|
|
309
|
-
|
|
310
|
-
return _newState;
|
|
311
|
-
}
|
|
312
|
-
|
|
313
|
-
case "LiveMap":
|
|
314
|
-
{
|
|
315
|
-
if (typeof state !== "object") {
|
|
316
|
-
throw new Error("Internal: received update on LiveMap but state was not an object");
|
|
317
|
-
}
|
|
318
|
-
|
|
319
|
-
var _newState2 = Object.assign({}, state);
|
|
320
|
-
|
|
321
|
-
for (var _key7 in update.updates) {
|
|
322
|
-
var _update$updates$_key3, _update$updates$_key4;
|
|
323
|
-
|
|
324
|
-
if (((_update$updates$_key3 = update.updates[_key7]) == null ? void 0 : _update$updates$_key3.type) === "update") {
|
|
325
|
-
_newState2[_key7] = lsonToJson(update.node.get(_key7));
|
|
326
|
-
} else if (((_update$updates$_key4 = update.updates[_key7]) == null ? void 0 : _update$updates$_key4.type) === "delete") {
|
|
327
|
-
delete _newState2[_key7];
|
|
328
|
-
}
|
|
329
|
-
}
|
|
330
|
-
|
|
331
|
-
return _newState2;
|
|
332
|
-
}
|
|
333
|
-
}
|
|
334
|
-
}
|
|
335
|
-
|
|
336
|
-
if (Array.isArray(state)) {
|
|
337
|
-
var newArray = [].concat(state);
|
|
338
|
-
newArray[pathItem] = patchImmutableNode(state[pathItem], path, update);
|
|
339
|
-
return newArray;
|
|
340
|
-
} else {
|
|
341
|
-
var _extends2;
|
|
342
|
-
|
|
343
|
-
return LiveObject._extends({}, state, (_extends2 = {}, _extends2[pathItem] = patchImmutableNode(state[pathItem], path, update), _extends2));
|
|
344
|
-
}
|
|
100
|
+
var _extends2, pathItem = path.pop();
|
|
101
|
+
if (void 0 === pathItem) switch (update.type) {
|
|
102
|
+
case "LiveObject":
|
|
103
|
+
if ("object" != typeof state) throw new Error("Internal: received update on LiveObject but state was not an object");
|
|
104
|
+
var newState = Object.assign({}, state);
|
|
105
|
+
for (var _key6 in update.updates) {
|
|
106
|
+
var _update$updates$_key, _update$updates$_key2;
|
|
107
|
+
if ("update" === (null == (_update$updates$_key = update.updates[_key6]) ? void 0 : _update$updates$_key.type)) {
|
|
108
|
+
var val = update.node.get(_key6);
|
|
109
|
+
void 0 !== val && (newState[_key6] = lsonToJson(val));
|
|
110
|
+
} else "delete" === (null == (_update$updates$_key2 = update.updates[_key6]) ? void 0 : _update$updates$_key2.type) && delete newState[_key6];
|
|
111
|
+
}
|
|
112
|
+
return newState;
|
|
113
|
+
|
|
114
|
+
case "LiveList":
|
|
115
|
+
if (!1 === Array.isArray(state)) throw new Error("Internal: received update on LiveList but state was not an array");
|
|
116
|
+
for (var _step2, _newState = state.map((function(x) {
|
|
117
|
+
return x;
|
|
118
|
+
})), _loop = function() {
|
|
119
|
+
var listUpdate = _step2.value;
|
|
120
|
+
"set" === listUpdate.type ? _newState = _newState.map((function(item, index) {
|
|
121
|
+
return index === listUpdate.index ? listUpdate.item : item;
|
|
122
|
+
})) : "insert" === listUpdate.type ? listUpdate.index === _newState.length ? _newState.push(lsonToJson(listUpdate.item)) : _newState = [].concat(_newState.slice(0, listUpdate.index), [ lsonToJson(listUpdate.item) ], _newState.slice(listUpdate.index)) : "delete" === listUpdate.type ? _newState.splice(listUpdate.index, 1) : "move" === listUpdate.type && (_newState = listUpdate.previousIndex > listUpdate.index ? [].concat(_newState.slice(0, listUpdate.index), [ lsonToJson(listUpdate.item) ], _newState.slice(listUpdate.index, listUpdate.previousIndex), _newState.slice(listUpdate.previousIndex + 1)) : [].concat(_newState.slice(0, listUpdate.previousIndex), _newState.slice(listUpdate.previousIndex + 1, listUpdate.index + 1), [ lsonToJson(listUpdate.item) ], _newState.slice(listUpdate.index + 1)));
|
|
123
|
+
}, _iterator2 = LiveObject._createForOfIteratorHelperLoose(update.updates); !(_step2 = _iterator2()).done; ) _loop();
|
|
124
|
+
return _newState;
|
|
125
|
+
|
|
126
|
+
case "LiveMap":
|
|
127
|
+
if ("object" != typeof state) throw new Error("Internal: received update on LiveMap but state was not an object");
|
|
128
|
+
var _newState2 = Object.assign({}, state);
|
|
129
|
+
for (var _key7 in update.updates) {
|
|
130
|
+
var _update$updates$_key3, _update$updates$_key4;
|
|
131
|
+
"update" === (null == (_update$updates$_key3 = update.updates[_key7]) ? void 0 : _update$updates$_key3.type) ? _newState2[_key7] = lsonToJson(update.node.get(_key7)) : "delete" === (null == (_update$updates$_key4 = update.updates[_key7]) ? void 0 : _update$updates$_key4.type) && delete _newState2[_key7];
|
|
132
|
+
}
|
|
133
|
+
return _newState2;
|
|
134
|
+
}
|
|
135
|
+
if (Array.isArray(state)) {
|
|
136
|
+
var newArray = [].concat(state);
|
|
137
|
+
return newArray[pathItem] = patchImmutableNode(state[pathItem], path, update), newArray;
|
|
138
|
+
}
|
|
139
|
+
return LiveObject._extends({}, state, ((_extends2 = {})[pathItem] = patchImmutableNode(state[pathItem], path, update),
|
|
140
|
+
_extends2));
|
|
345
141
|
}
|
|
346
142
|
|
|
347
|
-
Object.defineProperty(exports,
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
})
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
exports
|
|
143
|
+
Object.defineProperty(exports, "ClientMessageType", {
|
|
144
|
+
enumerable: !0,
|
|
145
|
+
get: function() {
|
|
146
|
+
return LiveObject.ClientMessageType;
|
|
147
|
+
}
|
|
148
|
+
}), Object.defineProperty(exports, "CrdtType", {
|
|
149
|
+
enumerable: !0,
|
|
150
|
+
get: function() {
|
|
151
|
+
return LiveObject.CrdtType;
|
|
152
|
+
}
|
|
153
|
+
}), Object.defineProperty(exports, "OpType", {
|
|
154
|
+
enumerable: !0,
|
|
155
|
+
get: function() {
|
|
156
|
+
return LiveObject.OpType;
|
|
157
|
+
}
|
|
158
|
+
}), Object.defineProperty(exports, "ServerMessageType", {
|
|
159
|
+
enumerable: !0,
|
|
160
|
+
get: function() {
|
|
161
|
+
return LiveObject.ServerMessageType;
|
|
162
|
+
}
|
|
163
|
+
}), Object.defineProperty(exports, "WebsocketCloseCodes", {
|
|
164
|
+
enumerable: !0,
|
|
165
|
+
get: function() {
|
|
166
|
+
return LiveObject.WebsocketCloseCodes;
|
|
167
|
+
}
|
|
168
|
+
}), exports.comparePosition = LiveObject.comparePosition, exports.deprecate = LiveObject.deprecate,
|
|
169
|
+
exports.deprecateIf = LiveObject.deprecateIf, exports.errorIf = LiveObject.errorIf,
|
|
170
|
+
exports.makePosition = LiveObject.makePosition, exports.throwUsageError = LiveObject.throwUsageError,
|
|
171
|
+
exports.lsonToJson = lsonToJson, exports.patchImmutableObject = function(state, updates) {
|
|
172
|
+
return updates.reduce((function(state, update) {
|
|
173
|
+
return function(state, update) {
|
|
174
|
+
var path = function(node) {
|
|
175
|
+
for (var path = []; null != node._parentKey && null != node._parent; ) node._parent instanceof LiveObject.LiveList ? path.push(node._parent._indexOfPosition(node._parentKey)) : path.push(node._parentKey),
|
|
176
|
+
node = node._parent;
|
|
177
|
+
return path;
|
|
178
|
+
}(update.node);
|
|
179
|
+
return patchImmutableNode(state, path, update);
|
|
180
|
+
}(state, update);
|
|
181
|
+
}), state);
|
|
182
|
+
}, exports.patchLiveObjectKey = patchLiveObjectKey;
|