reactronic 0.22.310 → 0.22.311
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/build/dist/source/Buffer.js +2 -6
- package/build/dist/source/Controller.js +1 -5
- package/build/dist/source/Logging.js +1 -4
- package/build/dist/source/Options.js +5 -9
- package/build/dist/source/Ref.js +6 -11
- package/build/dist/source/Rx.js +46 -57
- package/build/dist/source/Worker.js +1 -2
- package/build/dist/source/api.js +13 -42
- package/build/dist/source/impl/Changeset.js +87 -92
- package/build/dist/source/impl/Data.js +10 -17
- package/build/dist/source/impl/Hooks.js +54 -62
- package/build/dist/source/impl/Journal.js +22 -27
- package/build/dist/source/impl/Meta.js +1 -5
- package/build/dist/source/impl/Monitor.js +9 -14
- package/build/dist/source/impl/Operation.js +150 -156
- package/build/dist/source/impl/Transaction.js +27 -31
- package/build/dist/source/util/Dbg.js +4 -11
- package/build/dist/source/util/Sealant.js +5 -9
- package/build/dist/source/util/SealedArray.js +10 -14
- package/build/dist/source/util/SealedMap.js +8 -12
- package/build/dist/source/util/SealedSet.js +8 -12
- package/build/dist/source/util/Utils.js +4 -11
- package/package.json +5 -5
|
@@ -1,25 +1,22 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
const
|
|
9
|
-
const
|
|
10
|
-
|
|
11
|
-
exports.MAX_REVISION = Number.MAX_SAFE_INTEGER;
|
|
12
|
-
exports.UNDEFINED_REVISION = exports.MAX_REVISION - 1;
|
|
13
|
-
Object.defineProperty(Data_1.ObjectHandle.prototype, '#this', {
|
|
1
|
+
import { Utils, UNDEF } from '../util/Utils';
|
|
2
|
+
import { Log, misuse } from '../util/Dbg';
|
|
3
|
+
import { Sealant } from '../util/Sealant';
|
|
4
|
+
import { SealedArray } from '../util/SealedArray';
|
|
5
|
+
import { SealedMap } from '../util/SealedMap';
|
|
6
|
+
import { SealedSet } from '../util/SealedSet';
|
|
7
|
+
import { ObjectSnapshot, ObjectHandle, Subscription, Meta } from './Data';
|
|
8
|
+
export const MAX_REVISION = Number.MAX_SAFE_INTEGER;
|
|
9
|
+
export const UNDEFINED_REVISION = MAX_REVISION - 1;
|
|
10
|
+
Object.defineProperty(ObjectHandle.prototype, '#this', {
|
|
14
11
|
configurable: false, enumerable: false,
|
|
15
12
|
get() {
|
|
16
13
|
const result = {};
|
|
17
14
|
const data = Changeset.current().getRelevantSnapshot(this, '#this').data;
|
|
18
15
|
for (const m in data) {
|
|
19
16
|
const v = data[m];
|
|
20
|
-
if (v instanceof
|
|
17
|
+
if (v instanceof Subscription)
|
|
21
18
|
result[m] = v.content;
|
|
22
|
-
else if (v ===
|
|
19
|
+
else if (v === Meta.Nonreactive)
|
|
23
20
|
result[m] = this.data[m];
|
|
24
21
|
else
|
|
25
22
|
result[m] = v;
|
|
@@ -28,12 +25,12 @@ Object.defineProperty(Data_1.ObjectHandle.prototype, '#this', {
|
|
|
28
25
|
},
|
|
29
26
|
});
|
|
30
27
|
const EMPTY_ARRAY = Object.freeze([]);
|
|
31
|
-
const EMPTY_MAP =
|
|
32
|
-
class Changeset {
|
|
28
|
+
const EMPTY_MAP = Utils.freezeMap(new Map());
|
|
29
|
+
export class Changeset {
|
|
33
30
|
constructor(options) {
|
|
34
31
|
this.id = ++Changeset.idGen;
|
|
35
|
-
this.options = options !== null && options !== void 0 ? options :
|
|
36
|
-
this.revision =
|
|
32
|
+
this.options = options !== null && options !== void 0 ? options : DefaultSnapshotOptions;
|
|
33
|
+
this.revision = UNDEFINED_REVISION;
|
|
37
34
|
this.bumper = 100;
|
|
38
35
|
this.items = new Map();
|
|
39
36
|
this.reactions = [];
|
|
@@ -50,76 +47,76 @@ class Changeset {
|
|
|
50
47
|
}
|
|
51
48
|
if (!os) {
|
|
52
49
|
os = h.head;
|
|
53
|
-
while (os !==
|
|
50
|
+
while (os !== EMPTY_SNAPSHOT && os.changeset.timestamp > this.timestamp)
|
|
54
51
|
os = os.former.snapshot;
|
|
55
52
|
}
|
|
56
53
|
return os;
|
|
57
54
|
}
|
|
58
55
|
getRelevantSnapshot(h, m) {
|
|
59
56
|
const r = this.seekSnapshot(h, m);
|
|
60
|
-
if (r ===
|
|
61
|
-
throw
|
|
57
|
+
if (r === EMPTY_SNAPSHOT)
|
|
58
|
+
throw misuse(`object ${Dump.obj(h)} doesn't exist in snapshot v${this.revision} (${this.hint})`);
|
|
62
59
|
return r;
|
|
63
60
|
}
|
|
64
61
|
getEditableSnapshot(h, m, value, token) {
|
|
65
62
|
let os = this.seekSnapshot(h, m);
|
|
66
63
|
const existing = os.data[m];
|
|
67
|
-
if (existing !==
|
|
64
|
+
if (existing !== Meta.Nonreactive) {
|
|
68
65
|
if (this.isNewSnapshotRequired(h, os, m, existing, value, token)) {
|
|
69
66
|
this.bumpBy(os.changeset.timestamp);
|
|
70
|
-
const revision = m ===
|
|
71
|
-
const data = Object.assign({}, m ===
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
os = new
|
|
67
|
+
const revision = m === Meta.Handle ? 1 : os.revision + 1;
|
|
68
|
+
const data = Object.assign({}, m === Meta.Handle ? value : os.data);
|
|
69
|
+
Meta.set(data, Meta.Handle, h);
|
|
70
|
+
Meta.set(data, Meta.Revision, new Subscription(revision));
|
|
71
|
+
os = new ObjectSnapshot(this, os, data);
|
|
75
72
|
this.items.set(h, os);
|
|
76
73
|
h.editing = os;
|
|
77
74
|
h.editors++;
|
|
78
|
-
if (
|
|
79
|
-
|
|
75
|
+
if (Log.isOn && Log.opt.write)
|
|
76
|
+
Log.write('║', ' ⎘⎘', `${Dump.obj(h)} - new snapshot is created (revision ${revision})`);
|
|
80
77
|
}
|
|
81
78
|
}
|
|
82
79
|
else
|
|
83
|
-
os =
|
|
80
|
+
os = EMPTY_SNAPSHOT;
|
|
84
81
|
return os;
|
|
85
82
|
}
|
|
86
83
|
static takeSnapshot(obj) {
|
|
87
|
-
return obj[
|
|
84
|
+
return obj[Meta.Handle]['#this'];
|
|
88
85
|
}
|
|
89
86
|
static dispose(obj) {
|
|
90
87
|
const ctx = Changeset.edit();
|
|
91
|
-
const h =
|
|
88
|
+
const h = Meta.get(obj, Meta.Handle);
|
|
92
89
|
if (h !== undefined)
|
|
93
90
|
Changeset.doDispose(ctx, h);
|
|
94
91
|
}
|
|
95
92
|
static doDispose(ctx, h) {
|
|
96
|
-
const os = ctx.getEditableSnapshot(h,
|
|
97
|
-
if (os !==
|
|
93
|
+
const os = ctx.getEditableSnapshot(h, Meta.Revision, Meta.Undefined);
|
|
94
|
+
if (os !== EMPTY_SNAPSHOT)
|
|
98
95
|
os.disposed = true;
|
|
99
96
|
return os;
|
|
100
97
|
}
|
|
101
98
|
isNewSnapshotRequired(h, os, m, existing, value, token) {
|
|
102
|
-
if (this.sealed && os.changeset !==
|
|
103
|
-
throw
|
|
104
|
-
if (m !==
|
|
105
|
-
if (os.changeset !== this || os.former.snapshot !==
|
|
99
|
+
if (this.sealed && os.changeset !== EMPTY_SNAPSHOT.changeset)
|
|
100
|
+
throw misuse(`reactive property ${Dump.obj(h, m)} can only be modified inside transaction`);
|
|
101
|
+
if (m !== Meta.Handle && value !== Meta.Handle) {
|
|
102
|
+
if (os.changeset !== this || os.former.snapshot !== EMPTY_SNAPSHOT) {
|
|
106
103
|
if (this.options.token !== undefined && token !== this.options.token)
|
|
107
|
-
throw
|
|
104
|
+
throw misuse(`${this.hint} should not have side effects (trying to change ${Dump.snapshot(os, m)})`);
|
|
108
105
|
}
|
|
109
|
-
if (os ===
|
|
110
|
-
throw
|
|
106
|
+
if (os === EMPTY_SNAPSHOT)
|
|
107
|
+
throw misuse(`member ${Dump.snapshot(os, m)} doesn't exist in snapshot v${this.revision} (${this.hint})`);
|
|
111
108
|
}
|
|
112
109
|
return os.changeset !== this && !this.sealed;
|
|
113
110
|
}
|
|
114
111
|
acquire(outer) {
|
|
115
|
-
if (!this.sealed && this.revision ===
|
|
116
|
-
const ahead = this.options.token === undefined || outer.revision ===
|
|
112
|
+
if (!this.sealed && this.revision === UNDEFINED_REVISION) {
|
|
113
|
+
const ahead = this.options.token === undefined || outer.revision === UNDEFINED_REVISION;
|
|
117
114
|
this.revision = ahead ? Changeset.stampGen : outer.revision;
|
|
118
115
|
Changeset.pending.push(this);
|
|
119
116
|
if (Changeset.oldest === undefined)
|
|
120
117
|
Changeset.oldest = this;
|
|
121
|
-
if (
|
|
122
|
-
|
|
118
|
+
if (Log.isOn && Log.opt.transaction)
|
|
119
|
+
Log.write('╔══', `v${this.revision}`, `${this.hint}`);
|
|
123
120
|
}
|
|
124
121
|
}
|
|
125
122
|
bumpBy(timestamp) {
|
|
@@ -137,8 +134,8 @@ class Changeset {
|
|
|
137
134
|
conflicts = [];
|
|
138
135
|
conflicts.push(os);
|
|
139
136
|
}
|
|
140
|
-
if (
|
|
141
|
-
|
|
137
|
+
if (Log.isOn && Log.opt.transaction)
|
|
138
|
+
Log.write('╠╝', '', `${Dump.snapshot2(h, os.changeset)} is merged with ${Dump.snapshot2(h, h.head.changeset)} among ${merged} properties with ${os.conflicts.size} conflicts.`);
|
|
142
139
|
}
|
|
143
140
|
});
|
|
144
141
|
if (this.options.token === undefined) {
|
|
@@ -167,8 +164,8 @@ class Changeset {
|
|
|
167
164
|
if (headDisposed || oursDisposed) {
|
|
168
165
|
if (headDisposed !== oursDisposed) {
|
|
169
166
|
if (headDisposed || this.options.standalone !== 'disposal') {
|
|
170
|
-
if (
|
|
171
|
-
|
|
167
|
+
if (Log.isOn && Log.opt.change)
|
|
168
|
+
Log.write('║╠', '', `${Dump.snapshot2(h, ours.changeset, m)} <> ${Dump.snapshot2(h, head.changeset, m)}`, 0, ' *** CONFLICT ***');
|
|
172
169
|
ours.conflicts.set(m, head);
|
|
173
170
|
}
|
|
174
171
|
}
|
|
@@ -177,11 +174,11 @@ class Changeset {
|
|
|
177
174
|
const conflict = Changeset.isConflicting(head.data[m], ours.former.snapshot.data[m]);
|
|
178
175
|
if (conflict)
|
|
179
176
|
ours.conflicts.set(m, head);
|
|
180
|
-
if (
|
|
181
|
-
|
|
177
|
+
if (Log.isOn && Log.opt.change)
|
|
178
|
+
Log.write('║╠', '', `${Dump.snapshot2(h, ours.changeset, m)} ${conflict ? '<>' : '=='} ${Dump.snapshot2(h, head.changeset, m)}`, 0, conflict ? ' *** CONFLICT ***' : undefined);
|
|
182
179
|
}
|
|
183
180
|
});
|
|
184
|
-
|
|
181
|
+
Utils.copyAllMembers(merged, ours.data);
|
|
185
182
|
ours.former.snapshot = head;
|
|
186
183
|
return counter;
|
|
187
184
|
}
|
|
@@ -196,22 +193,22 @@ class Changeset {
|
|
|
196
193
|
h.head = os;
|
|
197
194
|
if (Changeset.garbageCollectionSummaryInterval < Number.MAX_SAFE_INTEGER) {
|
|
198
195
|
Changeset.totalObjectSnapshotCount++;
|
|
199
|
-
if (os.former.snapshot ===
|
|
196
|
+
if (os.former.snapshot === EMPTY_SNAPSHOT)
|
|
200
197
|
Changeset.totalObjectHandleCount++;
|
|
201
198
|
}
|
|
202
199
|
}
|
|
203
200
|
});
|
|
204
|
-
if (
|
|
205
|
-
if (
|
|
201
|
+
if (Log.isOn) {
|
|
202
|
+
if (Log.opt.change && !error) {
|
|
206
203
|
this.items.forEach((os, h) => {
|
|
207
204
|
const members = [];
|
|
208
205
|
os.changes.forEach((o, m) => members.push(m.toString()));
|
|
209
206
|
const s = members.join(', ');
|
|
210
|
-
|
|
207
|
+
Log.write('║', '√', `${Dump.snapshot2(h, os.changeset)} (${s}) is ${os.former.snapshot === EMPTY_SNAPSHOT ? 'constructed' : `applied on top of ${Dump.snapshot2(h, os.former.snapshot.changeset)}`}`);
|
|
211
208
|
});
|
|
212
209
|
}
|
|
213
|
-
if (
|
|
214
|
-
|
|
210
|
+
if (Log.opt.transaction)
|
|
211
|
+
Log.write(this.revision < UNDEFINED_REVISION ? '╚══' : '═══', `v${this.revision}`, `${this.hint} - ${error ? 'CANCEL' : 'APPLY'}(${this.items.size})${error ? ` - ${error}` : ''}`);
|
|
215
212
|
}
|
|
216
213
|
if (!error)
|
|
217
214
|
Changeset.propagateAllChangesThroughSubscriptions(this);
|
|
@@ -222,24 +219,24 @@ class Changeset {
|
|
|
222
219
|
os.changes.forEach((o, m) => Changeset.sealSubscription(os.data[m], m, h.proxy.constructor.name));
|
|
223
220
|
else
|
|
224
221
|
for (const m in os.former.snapshot.data)
|
|
225
|
-
os.data[m] =
|
|
226
|
-
if (
|
|
222
|
+
os.data[m] = Meta.Undefined;
|
|
223
|
+
if (Log.isOn)
|
|
227
224
|
Changeset.freezeObjectSnapshot(os);
|
|
228
225
|
}
|
|
229
226
|
static sealSubscription(subscription, m, typeName) {
|
|
230
|
-
if (subscription instanceof
|
|
227
|
+
if (subscription instanceof Subscription) {
|
|
231
228
|
const value = subscription.content;
|
|
232
229
|
if (value !== undefined && value !== null) {
|
|
233
|
-
const sealedType = Object.getPrototypeOf(value)[
|
|
230
|
+
const sealedType = Object.getPrototypeOf(value)[Sealant.SealedType];
|
|
234
231
|
if (sealedType)
|
|
235
|
-
subscription.content =
|
|
232
|
+
subscription.content = Sealant.seal(value, sealedType, typeName, m);
|
|
236
233
|
}
|
|
237
234
|
}
|
|
238
235
|
}
|
|
239
236
|
static freezeObjectSnapshot(os) {
|
|
240
237
|
Object.freeze(os.data);
|
|
241
|
-
|
|
242
|
-
|
|
238
|
+
Utils.freezeSet(os.changes);
|
|
239
|
+
Utils.freezeMap(os.conflicts);
|
|
243
240
|
return os;
|
|
244
241
|
}
|
|
245
242
|
triggerGarbageCollection() {
|
|
@@ -256,46 +253,45 @@ class Changeset {
|
|
|
256
253
|
Changeset.oldest = Changeset.pending[0];
|
|
257
254
|
const now = Date.now();
|
|
258
255
|
if (now - Changeset.lastGarbageCollectionSummaryTimestamp > Changeset.garbageCollectionSummaryInterval) {
|
|
259
|
-
|
|
256
|
+
Log.write('', '[G]', `Total object/snapshot count: ${Changeset.totalObjectHandleCount}/${Changeset.totalObjectSnapshotCount}`);
|
|
260
257
|
Changeset.lastGarbageCollectionSummaryTimestamp = now;
|
|
261
258
|
}
|
|
262
259
|
}
|
|
263
260
|
}
|
|
264
261
|
}
|
|
265
262
|
unlinkHistory() {
|
|
266
|
-
if (
|
|
267
|
-
|
|
263
|
+
if (Log.isOn && Log.opt.gc)
|
|
264
|
+
Log.write('', '[G]', `Dismiss history below v${this.revision}t${this.id} (${this.hint})`);
|
|
268
265
|
this.items.forEach((os, h) => {
|
|
269
|
-
if (
|
|
270
|
-
|
|
266
|
+
if (Log.isOn && Log.opt.gc && os.former.snapshot !== EMPTY_SNAPSHOT)
|
|
267
|
+
Log.write(' ', ' ', `${Dump.snapshot2(h, os.former.snapshot.changeset)} is ready for GC because overwritten by ${Dump.snapshot2(h, os.changeset)}`);
|
|
271
268
|
if (Changeset.garbageCollectionSummaryInterval < Number.MAX_SAFE_INTEGER) {
|
|
272
|
-
if (os.former.snapshot !==
|
|
269
|
+
if (os.former.snapshot !== EMPTY_SNAPSHOT)
|
|
273
270
|
Changeset.totalObjectSnapshotCount--;
|
|
274
271
|
if (os.disposed)
|
|
275
272
|
Changeset.totalObjectHandleCount--;
|
|
276
273
|
}
|
|
277
|
-
os.former.snapshot =
|
|
274
|
+
os.former.snapshot = EMPTY_SNAPSHOT;
|
|
278
275
|
});
|
|
279
276
|
this.items = EMPTY_MAP;
|
|
280
277
|
this.reactions = EMPTY_ARRAY;
|
|
281
|
-
if (
|
|
278
|
+
if (Log.isOn)
|
|
282
279
|
Object.freeze(this);
|
|
283
280
|
}
|
|
284
281
|
static _init() {
|
|
285
|
-
const boot =
|
|
282
|
+
const boot = EMPTY_SNAPSHOT.changeset;
|
|
286
283
|
boot.acquire(boot);
|
|
287
284
|
boot.applyOrDiscard();
|
|
288
285
|
boot.triggerGarbageCollection();
|
|
289
|
-
Changeset.freezeObjectSnapshot(
|
|
286
|
+
Changeset.freezeObjectSnapshot(EMPTY_SNAPSHOT);
|
|
290
287
|
Changeset.idGen = 100;
|
|
291
288
|
Changeset.stampGen = 101;
|
|
292
289
|
Changeset.oldest = undefined;
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
290
|
+
SealedArray.prototype;
|
|
291
|
+
SealedMap.prototype;
|
|
292
|
+
SealedSet.prototype;
|
|
296
293
|
}
|
|
297
294
|
}
|
|
298
|
-
exports.Changeset = Changeset;
|
|
299
295
|
Changeset.idGen = -1;
|
|
300
296
|
Changeset.stampGen = 1;
|
|
301
297
|
Changeset.pending = [];
|
|
@@ -304,20 +300,20 @@ Changeset.garbageCollectionSummaryInterval = Number.MAX_SAFE_INTEGER;
|
|
|
304
300
|
Changeset.lastGarbageCollectionSummaryTimestamp = Date.now();
|
|
305
301
|
Changeset.totalObjectHandleCount = 0;
|
|
306
302
|
Changeset.totalObjectSnapshotCount = 0;
|
|
307
|
-
Changeset.current =
|
|
308
|
-
Changeset.edit =
|
|
309
|
-
Changeset.markUsed =
|
|
310
|
-
Changeset.markEdited =
|
|
311
|
-
Changeset.isConflicting =
|
|
303
|
+
Changeset.current = UNDEF;
|
|
304
|
+
Changeset.edit = UNDEF;
|
|
305
|
+
Changeset.markUsed = UNDEF;
|
|
306
|
+
Changeset.markEdited = UNDEF;
|
|
307
|
+
Changeset.isConflicting = UNDEF;
|
|
312
308
|
Changeset.propagateAllChangesThroughSubscriptions = (changeset) => { };
|
|
313
309
|
Changeset.revokeAllSubscriptions = (changeset) => { };
|
|
314
310
|
Changeset.enqueueReactionsToRun = (reactions) => { };
|
|
315
|
-
class Dump {
|
|
311
|
+
export class Dump {
|
|
316
312
|
static obj(h, m, stamp, snapshotId, originSnapshotId, value) {
|
|
317
313
|
const member = m !== undefined ? `.${m.toString()}` : '';
|
|
318
314
|
let result;
|
|
319
315
|
if (h !== undefined) {
|
|
320
|
-
const v = value !== undefined && value !==
|
|
316
|
+
const v = value !== undefined && value !== Meta.Undefined ? `[=${Dump.valueHint(value)}]` : '';
|
|
321
317
|
if (stamp === undefined)
|
|
322
318
|
result = `${h.hint}${member}${v} #${h.id}`;
|
|
323
319
|
else
|
|
@@ -329,10 +325,10 @@ class Dump {
|
|
|
329
325
|
}
|
|
330
326
|
static snapshot2(h, s, m, o) {
|
|
331
327
|
var _a;
|
|
332
|
-
return Dump.obj(h, m, s.timestamp, s.id, o === null || o === void 0 ? void 0 : o.originSnapshotId, (_a = o === null || o === void 0 ? void 0 : o.content) !== null && _a !== void 0 ? _a :
|
|
328
|
+
return Dump.obj(h, m, s.timestamp, s.id, o === null || o === void 0 ? void 0 : o.originSnapshotId, (_a = o === null || o === void 0 ? void 0 : o.content) !== null && _a !== void 0 ? _a : Meta.Undefined);
|
|
333
329
|
}
|
|
334
330
|
static snapshot(os, m) {
|
|
335
|
-
const h =
|
|
331
|
+
const h = Meta.get(os.data, Meta.Handle);
|
|
336
332
|
const value = m !== undefined ? os.data[m] : undefined;
|
|
337
333
|
return Dump.obj(h, m, os.changeset.timestamp, os.changeset.id, value === null || value === void 0 ? void 0 : value.originSnapshotId);
|
|
338
334
|
}
|
|
@@ -349,10 +345,9 @@ class Dump {
|
|
|
349
345
|
return `${theirs.changeset.hint} (${Dump.snapshot(theirs, m)})`;
|
|
350
346
|
}
|
|
351
347
|
}
|
|
352
|
-
exports.Dump = Dump;
|
|
353
348
|
Dump.valueHint = (value, m) => '???';
|
|
354
|
-
|
|
355
|
-
|
|
349
|
+
export const EMPTY_SNAPSHOT = new ObjectSnapshot(new Changeset({ hint: '<empty>' }), undefined, {});
|
|
350
|
+
export const DefaultSnapshotOptions = Object.freeze({
|
|
356
351
|
hint: 'noname',
|
|
357
352
|
standalone: false,
|
|
358
353
|
journal: undefined,
|
|
@@ -1,38 +1,32 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const Meta_1 = require("./Meta");
|
|
6
|
-
var Meta_2 = require("./Meta");
|
|
7
|
-
Object.defineProperty(exports, "Meta", { enumerable: true, get: function () { return Meta_2.Meta; } });
|
|
8
|
-
class Subscription {
|
|
1
|
+
import { Log } from '../util/Dbg';
|
|
2
|
+
import { Meta } from './Meta';
|
|
3
|
+
export { Meta } from './Meta';
|
|
4
|
+
export class Subscription {
|
|
9
5
|
constructor(content) { this.content = content; }
|
|
10
6
|
get isOperation() { return false; }
|
|
11
7
|
get originSnapshotId() { return 0; }
|
|
12
8
|
}
|
|
13
|
-
|
|
14
|
-
class ObjectSnapshot {
|
|
9
|
+
export class ObjectSnapshot {
|
|
15
10
|
constructor(changeset, former, data) {
|
|
16
11
|
this.changeset = changeset;
|
|
17
12
|
this.former = { snapshot: former || this };
|
|
18
13
|
this.data = data;
|
|
19
14
|
this.changes = new Set();
|
|
20
15
|
this.conflicts = new Map();
|
|
21
|
-
if (
|
|
16
|
+
if (Log.isOn)
|
|
22
17
|
Object.freeze(this);
|
|
23
18
|
}
|
|
24
19
|
get revision() {
|
|
25
|
-
return this.data[
|
|
20
|
+
return this.data[Meta.Revision].content;
|
|
26
21
|
}
|
|
27
22
|
get disposed() { return this.revision < 0; }
|
|
28
23
|
set disposed(value) {
|
|
29
24
|
const rev = this.revision;
|
|
30
25
|
if (rev < 0 !== value)
|
|
31
|
-
this.data[
|
|
26
|
+
this.data[Meta.Revision].content = ~rev;
|
|
32
27
|
}
|
|
33
28
|
}
|
|
34
|
-
|
|
35
|
-
class ObjectHandle {
|
|
29
|
+
export class ObjectHandle {
|
|
36
30
|
constructor(data, proxy, handler, head, hint) {
|
|
37
31
|
this.id = ++ObjectHandle.generator;
|
|
38
32
|
this.data = data;
|
|
@@ -43,9 +37,8 @@ class ObjectHandle {
|
|
|
43
37
|
this.hint = hint;
|
|
44
38
|
}
|
|
45
39
|
static getHint(obj, full) {
|
|
46
|
-
const h =
|
|
40
|
+
const h = Meta.get(obj, Meta.Handle);
|
|
47
41
|
return h !== undefined ? (full ? `${h.hint}#${h.id}` : h.hint) : undefined;
|
|
48
42
|
}
|
|
49
43
|
}
|
|
50
|
-
exports.ObjectHandle = ObjectHandle;
|
|
51
44
|
ObjectHandle.generator = 19;
|