@liveblocks/client 0.14.0 → 0.15.0-alpha.1
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/lib/cjs/AbstractCrdt.d.ts +5 -3
- package/lib/cjs/AbstractCrdt.js +1 -4
- package/lib/cjs/LiveList.d.ts +8 -2
- package/lib/cjs/LiveList.js +84 -8
- package/lib/cjs/LiveMap.d.ts +5 -1
- package/lib/cjs/LiveMap.js +35 -3
- package/lib/cjs/LiveObject.d.ts +5 -1
- package/lib/cjs/LiveObject.js +65 -10
- package/lib/cjs/LiveRegister.d.ts +5 -1
- package/lib/cjs/LiveRegister.js +6 -0
- package/lib/cjs/immutable.d.ts +9 -0
- package/lib/cjs/immutable.js +272 -0
- package/lib/cjs/index.d.ts +1 -0
- package/lib/cjs/index.js +8 -1
- package/lib/cjs/room.d.ts +1 -1
- package/lib/cjs/room.js +34 -48
- package/lib/cjs/types.d.ts +20 -0
- package/lib/cjs/utils.d.ts +2 -0
- package/lib/cjs/utils.js +26 -1
- package/lib/esm/AbstractCrdt.d.ts +5 -3
- package/lib/esm/AbstractCrdt.js +1 -4
- package/lib/esm/LiveList.d.ts +8 -2
- package/lib/esm/LiveList.js +84 -8
- package/lib/esm/LiveMap.d.ts +5 -1
- package/lib/esm/LiveMap.js +35 -3
- package/lib/esm/LiveObject.d.ts +5 -1
- package/lib/esm/LiveObject.js +65 -10
- package/lib/esm/LiveRegister.d.ts +5 -1
- package/lib/esm/LiveRegister.js +6 -0
- package/lib/esm/immutable.d.ts +9 -0
- package/lib/esm/immutable.js +263 -0
- package/lib/esm/index.d.ts +1 -0
- package/lib/esm/index.js +1 -0
- package/lib/esm/room.d.ts +1 -1
- package/lib/esm/room.js +35 -49
- package/lib/esm/types.d.ts +20 -0
- package/lib/esm/utils.d.ts +2 -0
- package/lib/esm/utils.js +24 -0
- package/package.json +2 -2
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { Op, SerializedCrdt } from "./live";
|
|
2
|
+
import { StorageUpdate } from "./types";
|
|
2
3
|
export declare type ApplyResult = {
|
|
3
4
|
reverse: Op[];
|
|
4
|
-
modified:
|
|
5
|
+
modified: StorageUpdate;
|
|
5
6
|
} | {
|
|
6
7
|
modified: false;
|
|
7
8
|
};
|
|
@@ -10,7 +11,7 @@ export interface Doc {
|
|
|
10
11
|
generateOpId: () => string;
|
|
11
12
|
addItem: (id: string, item: AbstractCrdt) => void;
|
|
12
13
|
deleteItem: (id: string) => void;
|
|
13
|
-
dispatch: (ops: Op[], reverseOps: Op[],
|
|
14
|
+
dispatch: (ops: Op[], reverseOps: Op[], storageUpdates: Map<string, StorageUpdate>) => void;
|
|
14
15
|
}
|
|
15
16
|
export declare abstract class AbstractCrdt {
|
|
16
17
|
#private;
|
|
@@ -53,7 +54,7 @@ export declare abstract class AbstractCrdt {
|
|
|
53
54
|
/**
|
|
54
55
|
* INTERNAL
|
|
55
56
|
*/
|
|
56
|
-
abstract _detachChild(crdt: AbstractCrdt):
|
|
57
|
+
abstract _detachChild(crdt: AbstractCrdt): ApplyResult;
|
|
57
58
|
/**
|
|
58
59
|
* INTERNAL
|
|
59
60
|
*/
|
|
@@ -62,4 +63,5 @@ export declare abstract class AbstractCrdt {
|
|
|
62
63
|
* INTERNAL
|
|
63
64
|
*/
|
|
64
65
|
abstract _toSerializedCrdt(): SerializedCrdt;
|
|
66
|
+
abstract _getType(): string;
|
|
65
67
|
}
|
package/lib/cjs/AbstractCrdt.js
CHANGED
|
@@ -52,10 +52,7 @@ class AbstractCrdt {
|
|
|
52
52
|
switch (op.type) {
|
|
53
53
|
case live_1.OpType.DeleteCrdt: {
|
|
54
54
|
if (this._parent != null && this._parentKey != null) {
|
|
55
|
-
|
|
56
|
-
const reverse = this._serialize(this._parent._id, this._parentKey, __classPrivateFieldGet(this, _AbstractCrdt_doc, "f"));
|
|
57
|
-
this._parent._detachChild(this);
|
|
58
|
-
return { modified: parent, reverse };
|
|
55
|
+
return this._parent._detachChild(this);
|
|
59
56
|
}
|
|
60
57
|
return { modified: false };
|
|
61
58
|
}
|
package/lib/cjs/LiveList.d.ts
CHANGED
|
@@ -14,6 +14,7 @@ export declare class LiveList<T> extends AbstractCrdt {
|
|
|
14
14
|
* INTERNAL
|
|
15
15
|
*/
|
|
16
16
|
_serialize(parentId?: string, parentKey?: string, doc?: Doc): Op[];
|
|
17
|
+
_indexOfPosition(position: string): number;
|
|
17
18
|
/**
|
|
18
19
|
* INTERNAL
|
|
19
20
|
*/
|
|
@@ -29,15 +30,19 @@ export declare class LiveList<T> extends AbstractCrdt {
|
|
|
29
30
|
/**
|
|
30
31
|
* INTERNAL
|
|
31
32
|
*/
|
|
32
|
-
_detachChild(child: AbstractCrdt):
|
|
33
|
+
_detachChild(child: AbstractCrdt): ApplyResult;
|
|
33
34
|
/**
|
|
34
35
|
* INTERNAL
|
|
35
36
|
*/
|
|
36
|
-
_setChildKey(key: string, child: AbstractCrdt):
|
|
37
|
+
_setChildKey(key: string, child: AbstractCrdt, previousKey: string): ApplyResult;
|
|
37
38
|
/**
|
|
38
39
|
* INTERNAL
|
|
39
40
|
*/
|
|
40
41
|
_apply(op: Op, isLocal: boolean): ApplyResult;
|
|
42
|
+
/**
|
|
43
|
+
* INTERNAL
|
|
44
|
+
*/
|
|
45
|
+
_getType(): string;
|
|
41
46
|
/**
|
|
42
47
|
* INTERNAL
|
|
43
48
|
*/
|
|
@@ -73,6 +78,7 @@ export declare class LiveList<T> extends AbstractCrdt {
|
|
|
73
78
|
* Returns an Array of all the elements in the LiveList.
|
|
74
79
|
*/
|
|
75
80
|
toArray(): T[];
|
|
81
|
+
toCrdtArray(): AbstractCrdt[];
|
|
76
82
|
/**
|
|
77
83
|
* Tests whether all elements pass the test implemented by the provided function.
|
|
78
84
|
* @param predicate Function to test for each element, taking two arguments (the element and its index).
|
package/lib/cjs/LiveList.js
CHANGED
|
@@ -75,6 +75,9 @@ class LiveList extends AbstractCrdt_1.AbstractCrdt {
|
|
|
75
75
|
}
|
|
76
76
|
return ops;
|
|
77
77
|
}
|
|
78
|
+
_indexOfPosition(position) {
|
|
79
|
+
return __classPrivateFieldGet(this, _LiveList_items, "f").findIndex((item) => item[1] === position);
|
|
80
|
+
}
|
|
78
81
|
/**
|
|
79
82
|
* INTERNAL
|
|
80
83
|
*/
|
|
@@ -123,22 +126,38 @@ class LiveList extends AbstractCrdt_1.AbstractCrdt {
|
|
|
123
126
|
}
|
|
124
127
|
__classPrivateFieldGet(this, _LiveList_items, "f").push([child, newKey]);
|
|
125
128
|
__classPrivateFieldGet(this, _LiveList_items, "f").sort((itemA, itemB) => (0, position_1.compare)(itemA[1], itemB[1]));
|
|
126
|
-
|
|
129
|
+
const newIndex = __classPrivateFieldGet(this, _LiveList_items, "f").findIndex((entry) => entry[1] === newKey);
|
|
130
|
+
return {
|
|
131
|
+
reverse: [{ type: live_1.OpType.DeleteCrdt, id }],
|
|
132
|
+
modified: {
|
|
133
|
+
node: this,
|
|
134
|
+
type: "LiveList",
|
|
135
|
+
updates: [{ index: newIndex, type: "insert" }],
|
|
136
|
+
},
|
|
137
|
+
};
|
|
127
138
|
}
|
|
128
139
|
/**
|
|
129
140
|
* INTERNAL
|
|
130
141
|
*/
|
|
131
142
|
_detachChild(child) {
|
|
132
|
-
const indexToDelete = __classPrivateFieldGet(this, _LiveList_items, "f").findIndex((item) => item[0] === child);
|
|
133
|
-
__classPrivateFieldGet(this, _LiveList_items, "f").splice(indexToDelete, 1);
|
|
134
143
|
if (child) {
|
|
144
|
+
const reverse = this._serialize(this._id, child._parentKey, this._doc);
|
|
145
|
+
const indexToDelete = __classPrivateFieldGet(this, _LiveList_items, "f").findIndex((item) => item[0] === child);
|
|
146
|
+
__classPrivateFieldGet(this, _LiveList_items, "f").splice(indexToDelete, 1);
|
|
135
147
|
child._detach();
|
|
148
|
+
const storageUpdate = {
|
|
149
|
+
node: this,
|
|
150
|
+
type: "LiveList",
|
|
151
|
+
updates: [{ index: indexToDelete, type: "delete" }],
|
|
152
|
+
};
|
|
153
|
+
return { modified: storageUpdate, reverse };
|
|
136
154
|
}
|
|
155
|
+
return { modified: false };
|
|
137
156
|
}
|
|
138
157
|
/**
|
|
139
158
|
* INTERNAL
|
|
140
159
|
*/
|
|
141
|
-
_setChildKey(key, child) {
|
|
160
|
+
_setChildKey(key, child, previousKey) {
|
|
142
161
|
var _a;
|
|
143
162
|
child._setParentLink(this, key);
|
|
144
163
|
const index = __classPrivateFieldGet(this, _LiveList_items, "f").findIndex((entry) => entry[1] === key);
|
|
@@ -151,6 +170,21 @@ class LiveList extends AbstractCrdt_1.AbstractCrdt {
|
|
|
151
170
|
item[1] = key;
|
|
152
171
|
}
|
|
153
172
|
__classPrivateFieldGet(this, _LiveList_items, "f").sort((itemA, itemB) => (0, position_1.compare)(itemA[1], itemB[1]));
|
|
173
|
+
const newIndex = this._indexOfPosition(key);
|
|
174
|
+
return {
|
|
175
|
+
modified: {
|
|
176
|
+
node: this,
|
|
177
|
+
type: "LiveList",
|
|
178
|
+
updates: [{ index: newIndex, type: "insert" }],
|
|
179
|
+
},
|
|
180
|
+
reverse: [
|
|
181
|
+
{
|
|
182
|
+
type: live_1.OpType.SetParentKey,
|
|
183
|
+
id: item === null || item === void 0 ? void 0 : item[0]._id,
|
|
184
|
+
parentKey: previousKey,
|
|
185
|
+
},
|
|
186
|
+
],
|
|
187
|
+
};
|
|
154
188
|
}
|
|
155
189
|
/**
|
|
156
190
|
* INTERNAL
|
|
@@ -158,6 +192,12 @@ class LiveList extends AbstractCrdt_1.AbstractCrdt {
|
|
|
158
192
|
_apply(op, isLocal) {
|
|
159
193
|
return super._apply(op, isLocal);
|
|
160
194
|
}
|
|
195
|
+
/**
|
|
196
|
+
* INTERNAL
|
|
197
|
+
*/
|
|
198
|
+
_getType() {
|
|
199
|
+
return "LiveList";
|
|
200
|
+
}
|
|
161
201
|
/**
|
|
162
202
|
* INTERNAL
|
|
163
203
|
*/
|
|
@@ -198,10 +238,17 @@ class LiveList extends AbstractCrdt_1.AbstractCrdt {
|
|
|
198
238
|
value._setParentLink(this, position);
|
|
199
239
|
__classPrivateFieldGet(this, _LiveList_items, "f").push([value, position]);
|
|
200
240
|
__classPrivateFieldGet(this, _LiveList_items, "f").sort((itemA, itemB) => (0, position_1.compare)(itemA[1], itemB[1]));
|
|
241
|
+
const newIndex = __classPrivateFieldGet(this, _LiveList_items, "f").findIndex((entry) => entry[1] === position);
|
|
201
242
|
if (this._doc && this._id) {
|
|
202
243
|
const id = this._doc.generateId();
|
|
203
244
|
value._attach(id, this._doc);
|
|
204
|
-
|
|
245
|
+
const storageUpdates = new Map();
|
|
246
|
+
storageUpdates.set(this._id, {
|
|
247
|
+
node: this,
|
|
248
|
+
type: "LiveList",
|
|
249
|
+
updates: [{ index: newIndex, type: "insert" }],
|
|
250
|
+
});
|
|
251
|
+
this._doc.dispatch(value._serialize(this._id, position, this._doc), [{ type: live_1.OpType.DeleteCrdt, id }], storageUpdates);
|
|
205
252
|
}
|
|
206
253
|
}
|
|
207
254
|
/**
|
|
@@ -242,7 +289,17 @@ class LiveList extends AbstractCrdt_1.AbstractCrdt {
|
|
|
242
289
|
item[1] = position;
|
|
243
290
|
item[0]._setParentLink(this, position);
|
|
244
291
|
__classPrivateFieldGet(this, _LiveList_items, "f").sort((itemA, itemB) => (0, position_1.compare)(itemA[1], itemB[1]));
|
|
292
|
+
const newIndex = __classPrivateFieldGet(this, _LiveList_items, "f").findIndex((entry) => entry[1] === position);
|
|
245
293
|
if (this._doc && this._id) {
|
|
294
|
+
const storageUpdates = new Map();
|
|
295
|
+
storageUpdates.set(this._id, {
|
|
296
|
+
node: this,
|
|
297
|
+
type: "LiveList",
|
|
298
|
+
updates: [
|
|
299
|
+
{ index: index, type: "delete" },
|
|
300
|
+
{ index: newIndex, type: "insert" },
|
|
301
|
+
],
|
|
302
|
+
});
|
|
246
303
|
this._doc.dispatch([
|
|
247
304
|
{
|
|
248
305
|
type: live_1.OpType.SetParentKey,
|
|
@@ -256,7 +313,7 @@ class LiveList extends AbstractCrdt_1.AbstractCrdt {
|
|
|
256
313
|
id: item[0]._id,
|
|
257
314
|
parentKey: previousPosition,
|
|
258
315
|
},
|
|
259
|
-
],
|
|
316
|
+
], storageUpdates);
|
|
260
317
|
}
|
|
261
318
|
}
|
|
262
319
|
/**
|
|
@@ -273,13 +330,19 @@ class LiveList extends AbstractCrdt_1.AbstractCrdt {
|
|
|
273
330
|
if (this._doc) {
|
|
274
331
|
const childRecordId = item[0]._id;
|
|
275
332
|
if (childRecordId) {
|
|
333
|
+
const storageUpdates = new Map();
|
|
334
|
+
storageUpdates.set(this._id, {
|
|
335
|
+
node: this,
|
|
336
|
+
type: "LiveList",
|
|
337
|
+
updates: [{ index: index, type: "delete" }],
|
|
338
|
+
});
|
|
276
339
|
this._doc.dispatch([
|
|
277
340
|
{
|
|
278
341
|
id: childRecordId,
|
|
279
342
|
opId: this._doc.generateOpId(),
|
|
280
343
|
type: live_1.OpType.DeleteCrdt,
|
|
281
344
|
},
|
|
282
|
-
], item[0]._serialize(this._id, item[1]),
|
|
345
|
+
], item[0]._serialize(this._id, item[1]), storageUpdates);
|
|
283
346
|
}
|
|
284
347
|
}
|
|
285
348
|
}
|
|
@@ -287,16 +350,26 @@ class LiveList extends AbstractCrdt_1.AbstractCrdt {
|
|
|
287
350
|
if (this._doc) {
|
|
288
351
|
let ops = [];
|
|
289
352
|
let reverseOps = [];
|
|
353
|
+
let updateDelta = [];
|
|
354
|
+
let i = 0;
|
|
290
355
|
for (const item of __classPrivateFieldGet(this, _LiveList_items, "f")) {
|
|
291
356
|
item[0]._detach();
|
|
292
357
|
const childId = item[0]._id;
|
|
293
358
|
if (childId) {
|
|
294
359
|
ops.push({ id: childId, type: live_1.OpType.DeleteCrdt });
|
|
295
360
|
reverseOps.push(...item[0]._serialize(this._id, item[1]));
|
|
361
|
+
updateDelta.push({ index: i, type: "delete" });
|
|
296
362
|
}
|
|
363
|
+
i++;
|
|
297
364
|
}
|
|
298
365
|
__classPrivateFieldSet(this, _LiveList_items, [], "f");
|
|
299
|
-
|
|
366
|
+
const storageUpdates = new Map();
|
|
367
|
+
storageUpdates.set(this._id, {
|
|
368
|
+
node: this,
|
|
369
|
+
type: "LiveList",
|
|
370
|
+
updates: updateDelta,
|
|
371
|
+
});
|
|
372
|
+
this._doc.dispatch(ops, reverseOps, storageUpdates);
|
|
300
373
|
}
|
|
301
374
|
else {
|
|
302
375
|
for (const item of __classPrivateFieldGet(this, _LiveList_items, "f")) {
|
|
@@ -311,6 +384,9 @@ class LiveList extends AbstractCrdt_1.AbstractCrdt {
|
|
|
311
384
|
toArray() {
|
|
312
385
|
return __classPrivateFieldGet(this, _LiveList_items, "f").map((entry) => (0, utils_1.selfOrRegisterValue)(entry[0]));
|
|
313
386
|
}
|
|
387
|
+
toCrdtArray() {
|
|
388
|
+
return __classPrivateFieldGet(this, _LiveList_items, "f").map((entry) => entry[0]);
|
|
389
|
+
}
|
|
314
390
|
/**
|
|
315
391
|
* Tests whether all elements pass the test implemented by the provided function.
|
|
316
392
|
* @param predicate Function to test for each element, taking two arguments (the element and its index).
|
package/lib/cjs/LiveMap.d.ts
CHANGED
|
@@ -31,7 +31,11 @@ export declare class LiveMap<TKey extends string, TValue> extends AbstractCrdt {
|
|
|
31
31
|
/**
|
|
32
32
|
* INTERNAL
|
|
33
33
|
*/
|
|
34
|
-
_detachChild(child: AbstractCrdt):
|
|
34
|
+
_detachChild(child: AbstractCrdt): ApplyResult;
|
|
35
|
+
/**
|
|
36
|
+
* INTERNAL
|
|
37
|
+
*/
|
|
38
|
+
_getType(): string;
|
|
35
39
|
/**
|
|
36
40
|
* INTERNAL
|
|
37
41
|
*/
|
package/lib/cjs/LiveMap.js
CHANGED
|
@@ -116,7 +116,14 @@ class LiveMap extends AbstractCrdt_1.AbstractCrdt {
|
|
|
116
116
|
child._setParentLink(this, key);
|
|
117
117
|
child._attach(id, this._doc);
|
|
118
118
|
__classPrivateFieldGet(this, _LiveMap_map, "f").set(key, child);
|
|
119
|
-
return {
|
|
119
|
+
return {
|
|
120
|
+
modified: {
|
|
121
|
+
node: this,
|
|
122
|
+
type: "LiveMap",
|
|
123
|
+
updates: { [key]: { type: "update" } },
|
|
124
|
+
},
|
|
125
|
+
reverse,
|
|
126
|
+
};
|
|
120
127
|
}
|
|
121
128
|
/**
|
|
122
129
|
* INTERNAL
|
|
@@ -131,12 +138,25 @@ class LiveMap extends AbstractCrdt_1.AbstractCrdt {
|
|
|
131
138
|
* INTERNAL
|
|
132
139
|
*/
|
|
133
140
|
_detachChild(child) {
|
|
141
|
+
const reverse = this._serialize(this._id, child._parentKey, this._doc);
|
|
134
142
|
for (const [key, value] of __classPrivateFieldGet(this, _LiveMap_map, "f")) {
|
|
135
143
|
if (value === child) {
|
|
136
144
|
__classPrivateFieldGet(this, _LiveMap_map, "f").delete(key);
|
|
137
145
|
}
|
|
138
146
|
}
|
|
139
147
|
child._detach();
|
|
148
|
+
const storageUpdate = {
|
|
149
|
+
node: this,
|
|
150
|
+
type: "LiveMap",
|
|
151
|
+
updates: { [child._parentKey]: { type: "delete" } },
|
|
152
|
+
};
|
|
153
|
+
return { modified: storageUpdate, reverse };
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* INTERNAL
|
|
157
|
+
*/
|
|
158
|
+
_getType() {
|
|
159
|
+
return "LiveMap";
|
|
140
160
|
}
|
|
141
161
|
/**
|
|
142
162
|
* INTERNAL
|
|
@@ -177,9 +197,15 @@ class LiveMap extends AbstractCrdt_1.AbstractCrdt {
|
|
|
177
197
|
if (this._doc && this._id) {
|
|
178
198
|
const id = this._doc.generateId();
|
|
179
199
|
item._attach(id, this._doc);
|
|
200
|
+
const storageUpdates = new Map();
|
|
201
|
+
storageUpdates.set(this._id, {
|
|
202
|
+
node: this,
|
|
203
|
+
type: "LiveMap",
|
|
204
|
+
updates: { [key]: { type: "update" } },
|
|
205
|
+
});
|
|
180
206
|
this._doc.dispatch(item._serialize(this._id, key, this._doc), oldValue
|
|
181
207
|
? oldValue._serialize(this._id, key)
|
|
182
|
-
: [{ type: live_1.OpType.DeleteCrdt, id }],
|
|
208
|
+
: [{ type: live_1.OpType.DeleteCrdt, id }], storageUpdates);
|
|
183
209
|
}
|
|
184
210
|
}
|
|
185
211
|
/**
|
|
@@ -207,13 +233,19 @@ class LiveMap extends AbstractCrdt_1.AbstractCrdt {
|
|
|
207
233
|
}
|
|
208
234
|
item._detach();
|
|
209
235
|
if (this._doc && item._id) {
|
|
236
|
+
const storageUpdates = new Map();
|
|
237
|
+
storageUpdates.set(this._id, {
|
|
238
|
+
node: this,
|
|
239
|
+
type: "LiveMap",
|
|
240
|
+
updates: { [key]: { type: "delete" } },
|
|
241
|
+
});
|
|
210
242
|
this._doc.dispatch([
|
|
211
243
|
{
|
|
212
244
|
type: live_1.OpType.DeleteCrdt,
|
|
213
245
|
id: item._id,
|
|
214
246
|
opId: this._doc.generateOpId(),
|
|
215
247
|
},
|
|
216
|
-
], item._serialize(this._id, key),
|
|
248
|
+
], item._serialize(this._id, key), storageUpdates);
|
|
217
249
|
}
|
|
218
250
|
__classPrivateFieldGet(this, _LiveMap_map, "f").delete(key);
|
|
219
251
|
return true;
|
package/lib/cjs/LiveObject.d.ts
CHANGED
|
@@ -31,7 +31,7 @@ export declare class LiveObject<T extends Record<string, any> = Record<string, a
|
|
|
31
31
|
/**
|
|
32
32
|
* INTERNAL
|
|
33
33
|
*/
|
|
34
|
-
_detachChild(child: AbstractCrdt):
|
|
34
|
+
_detachChild(child: AbstractCrdt): ApplyResult;
|
|
35
35
|
/**
|
|
36
36
|
* INTERNAL
|
|
37
37
|
*/
|
|
@@ -48,6 +48,10 @@ export declare class LiveObject<T extends Record<string, any> = Record<string, a
|
|
|
48
48
|
* INTERNAL
|
|
49
49
|
*/
|
|
50
50
|
_toSerializedCrdt(): SerializedCrdt;
|
|
51
|
+
/**
|
|
52
|
+
* INTERNAL
|
|
53
|
+
*/
|
|
54
|
+
_getType(): string;
|
|
51
55
|
/**
|
|
52
56
|
* Transform the LiveObject into a javascript object
|
|
53
57
|
*/
|
package/lib/cjs/LiveObject.js
CHANGED
|
@@ -133,20 +133,37 @@ class LiveObject extends AbstractCrdt_1.AbstractCrdt {
|
|
|
133
133
|
__classPrivateFieldGet(this, _LiveObject_map, "f").set(key, child);
|
|
134
134
|
child._setParentLink(this, key);
|
|
135
135
|
child._attach(id, this._doc);
|
|
136
|
-
return {
|
|
136
|
+
return {
|
|
137
|
+
reverse,
|
|
138
|
+
modified: {
|
|
139
|
+
node: this,
|
|
140
|
+
type: "LiveObject",
|
|
141
|
+
updates: { [key]: { type: "update" } },
|
|
142
|
+
},
|
|
143
|
+
};
|
|
137
144
|
}
|
|
138
145
|
/**
|
|
139
146
|
* INTERNAL
|
|
140
147
|
*/
|
|
141
148
|
_detachChild(child) {
|
|
142
|
-
for (const [key, value] of __classPrivateFieldGet(this, _LiveObject_map, "f")) {
|
|
143
|
-
if (value === child) {
|
|
144
|
-
__classPrivateFieldGet(this, _LiveObject_map, "f").delete(key);
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
149
|
if (child) {
|
|
150
|
+
const reverse = this._serialize(this._id, child._parentKey, this._doc);
|
|
151
|
+
for (const [key, value] of __classPrivateFieldGet(this, _LiveObject_map, "f")) {
|
|
152
|
+
if (value === child) {
|
|
153
|
+
__classPrivateFieldGet(this, _LiveObject_map, "f").delete(key);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
148
156
|
child._detach();
|
|
157
|
+
const storageUpdate = {
|
|
158
|
+
node: this,
|
|
159
|
+
type: "LiveObject",
|
|
160
|
+
updates: {
|
|
161
|
+
[child._parentKey]: { type: "delete" },
|
|
162
|
+
},
|
|
163
|
+
};
|
|
164
|
+
return { modified: storageUpdate, reverse };
|
|
149
165
|
}
|
|
166
|
+
return { modified: false };
|
|
150
167
|
}
|
|
151
168
|
/**
|
|
152
169
|
* INTERNAL
|
|
@@ -192,6 +209,12 @@ class LiveObject extends AbstractCrdt_1.AbstractCrdt {
|
|
|
192
209
|
data: this.toObject(),
|
|
193
210
|
};
|
|
194
211
|
}
|
|
212
|
+
/**
|
|
213
|
+
* INTERNAL
|
|
214
|
+
*/
|
|
215
|
+
_getType() {
|
|
216
|
+
return "LiveObject";
|
|
217
|
+
}
|
|
195
218
|
/**
|
|
196
219
|
* Transform the LiveObject into a javascript object
|
|
197
220
|
*/
|
|
@@ -246,6 +269,12 @@ class LiveObject extends AbstractCrdt_1.AbstractCrdt {
|
|
|
246
269
|
];
|
|
247
270
|
}
|
|
248
271
|
__classPrivateFieldGet(this, _LiveObject_map, "f").delete(keyAsString);
|
|
272
|
+
const storageUpdates = new Map();
|
|
273
|
+
storageUpdates.set(this._id, {
|
|
274
|
+
node: this,
|
|
275
|
+
type: "LiveObject",
|
|
276
|
+
updates: { [key]: { type: "delete" } },
|
|
277
|
+
});
|
|
249
278
|
this._doc.dispatch([
|
|
250
279
|
{
|
|
251
280
|
type: live_1.OpType.DeleteObjectKey,
|
|
@@ -253,7 +282,7 @@ class LiveObject extends AbstractCrdt_1.AbstractCrdt {
|
|
|
253
282
|
id: this._id,
|
|
254
283
|
opId: this._doc.generateOpId(),
|
|
255
284
|
},
|
|
256
|
-
], reverse,
|
|
285
|
+
], reverse, storageUpdates);
|
|
257
286
|
}
|
|
258
287
|
/**
|
|
259
288
|
* Adds or updates multiple properties at once with an object.
|
|
@@ -283,6 +312,7 @@ class LiveObject extends AbstractCrdt_1.AbstractCrdt {
|
|
|
283
312
|
type: live_1.OpType.UpdateObject,
|
|
284
313
|
data: {},
|
|
285
314
|
};
|
|
315
|
+
const updateDelta = {};
|
|
286
316
|
for (const key in overrides) {
|
|
287
317
|
__classPrivateFieldGet(this, _LiveObject_propToLastUpdate, "f").set(key, opId);
|
|
288
318
|
const oldValue = __classPrivateFieldGet(this, _LiveObject_map, "f").get(key);
|
|
@@ -306,6 +336,7 @@ class LiveObject extends AbstractCrdt_1.AbstractCrdt {
|
|
|
306
336
|
updatedProps[key] = newValue;
|
|
307
337
|
}
|
|
308
338
|
__classPrivateFieldGet(this, _LiveObject_map, "f").set(key, newValue);
|
|
339
|
+
updateDelta[key] = { type: "update" };
|
|
309
340
|
}
|
|
310
341
|
if (Object.keys(reverseUpdateOp.data).length !== 0) {
|
|
311
342
|
reverseOps.unshift(reverseUpdateOp);
|
|
@@ -318,7 +349,13 @@ class LiveObject extends AbstractCrdt_1.AbstractCrdt {
|
|
|
318
349
|
data: updatedProps,
|
|
319
350
|
});
|
|
320
351
|
}
|
|
321
|
-
|
|
352
|
+
const storageUpdates = new Map();
|
|
353
|
+
storageUpdates.set(this._id, {
|
|
354
|
+
node: this,
|
|
355
|
+
type: "LiveObject",
|
|
356
|
+
updates: updateDelta,
|
|
357
|
+
});
|
|
358
|
+
this._doc.dispatch(ops, reverseOps, storageUpdates);
|
|
322
359
|
}
|
|
323
360
|
}
|
|
324
361
|
exports.LiveObject = LiveObject;
|
|
@@ -344,6 +381,7 @@ _LiveObject_map = new WeakMap(), _LiveObject_propToLastUpdate = new WeakMap(), _
|
|
|
344
381
|
reverse.push({ type: live_1.OpType.DeleteObjectKey, id: this._id, key });
|
|
345
382
|
}
|
|
346
383
|
}
|
|
384
|
+
let updateDelta = {};
|
|
347
385
|
for (const key in op.data) {
|
|
348
386
|
if (isLocal) {
|
|
349
387
|
__classPrivateFieldGet(this, _LiveObject_propToLastUpdate, "f").set(key, op.opId);
|
|
@@ -366,12 +404,22 @@ _LiveObject_map = new WeakMap(), _LiveObject_propToLastUpdate = new WeakMap(), _
|
|
|
366
404
|
oldValue._detach();
|
|
367
405
|
}
|
|
368
406
|
isModified = true;
|
|
407
|
+
updateDelta[key] = { type: "update" };
|
|
369
408
|
__classPrivateFieldGet(this, _LiveObject_map, "f").set(key, op.data[key]);
|
|
370
409
|
}
|
|
371
410
|
if (Object.keys(reverseUpdate.data).length !== 0) {
|
|
372
411
|
reverse.unshift(reverseUpdate);
|
|
373
412
|
}
|
|
374
|
-
return isModified
|
|
413
|
+
return isModified
|
|
414
|
+
? {
|
|
415
|
+
modified: {
|
|
416
|
+
node: this,
|
|
417
|
+
type: "LiveObject",
|
|
418
|
+
updates: updateDelta,
|
|
419
|
+
},
|
|
420
|
+
reverse,
|
|
421
|
+
}
|
|
422
|
+
: { modified: false };
|
|
375
423
|
}, _LiveObject_applyDeleteObjectKey = function _LiveObject_applyDeleteObjectKey(op) {
|
|
376
424
|
const key = op.key;
|
|
377
425
|
// If property does not exist, exit without notifying
|
|
@@ -394,5 +442,12 @@ _LiveObject_map = new WeakMap(), _LiveObject_propToLastUpdate = new WeakMap(), _
|
|
|
394
442
|
];
|
|
395
443
|
}
|
|
396
444
|
__classPrivateFieldGet(this, _LiveObject_map, "f").delete(key);
|
|
397
|
-
return {
|
|
445
|
+
return {
|
|
446
|
+
modified: {
|
|
447
|
+
node: this,
|
|
448
|
+
type: "LiveObject",
|
|
449
|
+
updates: { [op.key]: { type: "delete" } },
|
|
450
|
+
},
|
|
451
|
+
reverse,
|
|
452
|
+
};
|
|
398
453
|
};
|
|
@@ -20,6 +20,10 @@ export declare class LiveRegister<TValue = any> extends AbstractCrdt {
|
|
|
20
20
|
*/
|
|
21
21
|
_toSerializedCrdt(): SerializedCrdt;
|
|
22
22
|
_attachChild(id: string, key: string, crdt: AbstractCrdt, isLocal: boolean): ApplyResult;
|
|
23
|
-
_detachChild(crdt: AbstractCrdt):
|
|
23
|
+
_detachChild(crdt: AbstractCrdt): ApplyResult;
|
|
24
24
|
_apply(op: Op, isLocal: boolean): ApplyResult;
|
|
25
|
+
/**
|
|
26
|
+
* INTERNAL
|
|
27
|
+
*/
|
|
28
|
+
_getType(): string;
|
|
25
29
|
}
|
package/lib/cjs/LiveRegister.js
CHANGED
|
@@ -77,6 +77,12 @@ class LiveRegister extends AbstractCrdt_1.AbstractCrdt {
|
|
|
77
77
|
_apply(op, isLocal) {
|
|
78
78
|
return super._apply(op, isLocal);
|
|
79
79
|
}
|
|
80
|
+
/**
|
|
81
|
+
* INTERNAL
|
|
82
|
+
*/
|
|
83
|
+
_getType() {
|
|
84
|
+
return "LiveRegister";
|
|
85
|
+
}
|
|
80
86
|
}
|
|
81
87
|
exports.LiveRegister = LiveRegister;
|
|
82
88
|
_LiveRegister_data = new WeakMap();
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { LiveList } from "./LiveList";
|
|
2
|
+
import { LiveObject } from "./LiveObject";
|
|
3
|
+
import { StorageUpdate } from "./types";
|
|
4
|
+
export declare function liveObjectToJson(liveObject: LiveObject<any>): any;
|
|
5
|
+
export declare function liveNodeToJson(value: any): any;
|
|
6
|
+
export declare function patchLiveList<T>(liveList: LiveList<T>, prev: Array<T>, next: Array<T>): void;
|
|
7
|
+
export declare function patchLiveObjectKey<T>(liveObject: LiveObject<T>, key: keyof T, prev: any, next: any): void;
|
|
8
|
+
export declare function patchLiveObject<T extends Record<string, any>>(root: LiveObject<T>, prev: T, next: T): void;
|
|
9
|
+
export declare function patchImmutableObject<T>(state: T, updates: StorageUpdate[]): T;
|