@shaxpir/duiduidui-models 1.3.3 → 1.3.4
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/models/Model.d.ts +2 -0
- package/dist/models/Model.js +13 -2
- package/dist/repo/ShareSync.js +24 -5
- package/package.json +1 -1
package/dist/models/Model.d.ts
CHANGED
|
@@ -12,6 +12,8 @@ export declare abstract class Model {
|
|
|
12
12
|
private _isForbidden;
|
|
13
13
|
private _shouldPerformModelChangeAnalysis;
|
|
14
14
|
private _dataBeforeOpBatch;
|
|
15
|
+
private _hasEventListeners;
|
|
16
|
+
private _setupEventListeners;
|
|
15
17
|
private _clearEventListeners;
|
|
16
18
|
protected shareSync: ShareSync;
|
|
17
19
|
private _subscribingPromise;
|
package/dist/models/Model.js
CHANGED
|
@@ -8,6 +8,7 @@ const ChangeModel_1 = require("./ChangeModel");
|
|
|
8
8
|
class Model {
|
|
9
9
|
constructor(doc, shouldAcquire, shareSync) {
|
|
10
10
|
this._dataBeforeOpBatch = null;
|
|
11
|
+
this._setupEventListeners = null;
|
|
11
12
|
this._clearEventListeners = null;
|
|
12
13
|
this._subscribingPromise = null;
|
|
13
14
|
this._acquireCount = 0;
|
|
@@ -16,6 +17,7 @@ class Model {
|
|
|
16
17
|
model.shareSync = shareSync;
|
|
17
18
|
model._isDisposed = false;
|
|
18
19
|
model._isForbidden = false;
|
|
20
|
+
model._hasEventListeners = false;
|
|
19
21
|
// When a model is newly created, or retrieved via a "fetch query", treat that as an implicit
|
|
20
22
|
// call to "acquire", since the SharedDB doc object will eventually need to be disposed.
|
|
21
23
|
if (shouldAcquire) {
|
|
@@ -46,12 +48,18 @@ class Model {
|
|
|
46
48
|
shaxpir_common_1.Dispatch.publish(Model.CHANGED, change);
|
|
47
49
|
}
|
|
48
50
|
};
|
|
49
|
-
|
|
50
|
-
|
|
51
|
+
this._setupEventListeners = function () {
|
|
52
|
+
if (model.doc && model.doc.on) {
|
|
53
|
+
model.doc.on('before op batch', onBeforeOpBatch);
|
|
54
|
+
model.doc.on('op batch', onOpBatch);
|
|
55
|
+
model._hasEventListeners = true;
|
|
56
|
+
}
|
|
57
|
+
};
|
|
51
58
|
this._clearEventListeners = function () {
|
|
52
59
|
if (model.doc && model.doc.off) {
|
|
53
60
|
model.doc.off('before op batch', onBeforeOpBatch);
|
|
54
61
|
model.doc.off('op batch', onOpBatch);
|
|
62
|
+
model._hasEventListeners = false;
|
|
55
63
|
}
|
|
56
64
|
};
|
|
57
65
|
}
|
|
@@ -78,6 +86,9 @@ class Model {
|
|
|
78
86
|
}
|
|
79
87
|
async acquire(minVersion) {
|
|
80
88
|
this._acquireCount++;
|
|
89
|
+
if (!this._hasEventListeners) {
|
|
90
|
+
this._setupEventListeners();
|
|
91
|
+
}
|
|
81
92
|
if (minVersion) {
|
|
82
93
|
this.log(`ACQUIRE: (${this.compoundKey}) at minVersion '${minVersion}'; acquireCount = ${this.acquireCount}`);
|
|
83
94
|
return this.ensureRecentData(minVersion);
|
package/dist/repo/ShareSync.js
CHANGED
|
@@ -45,6 +45,7 @@ const Content_1 = require("../models/Content");
|
|
|
45
45
|
const ContentKind_1 = require("../models/ContentKind");
|
|
46
46
|
const Device_1 = require("../models/Device");
|
|
47
47
|
const Manifest_1 = require("../models/Manifest");
|
|
48
|
+
const Session_1 = require("../models/Session");
|
|
48
49
|
const User_1 = require("../models/User");
|
|
49
50
|
// Register the ShareDB types
|
|
50
51
|
const Json1 = __importStar(require("./PermissiveJson1"));
|
|
@@ -335,18 +336,36 @@ class ShareSync {
|
|
|
335
336
|
}
|
|
336
337
|
wrap(kind, doc, shouldAcquire) {
|
|
337
338
|
const shareSync = this;
|
|
338
|
-
if (kind === ContentKind_1.ContentKind.
|
|
339
|
+
if (kind === ContentKind_1.ContentKind.DEVICE) {
|
|
340
|
+
return new Device_1.Device(doc, shouldAcquire, shareSync);
|
|
341
|
+
}
|
|
342
|
+
else if (kind === ContentKind_1.ContentKind.MANIFEST) {
|
|
339
343
|
return new Manifest_1.Manifest(doc, shouldAcquire, shareSync);
|
|
340
344
|
}
|
|
341
|
-
else if (kind === ContentKind_1.ContentKind.
|
|
342
|
-
return new
|
|
345
|
+
else if (kind === ContentKind_1.ContentKind.METRIC) {
|
|
346
|
+
return new models_1.Metric(doc, shouldAcquire, shareSync);
|
|
343
347
|
}
|
|
344
|
-
else if (kind === ContentKind_1.ContentKind.
|
|
345
|
-
return new
|
|
348
|
+
else if (kind === ContentKind_1.ContentKind.MEDIA) {
|
|
349
|
+
return new models_1.Media(doc, shouldAcquire, shareSync);
|
|
346
350
|
}
|
|
347
351
|
else if (kind === ContentKind_1.ContentKind.PROFILE) {
|
|
348
352
|
return new models_1.Profile(doc, shouldAcquire, shareSync);
|
|
349
353
|
}
|
|
354
|
+
else if (kind === ContentKind_1.ContentKind.PROGRESS) {
|
|
355
|
+
return new models_1.Progress(doc, shouldAcquire, shareSync);
|
|
356
|
+
}
|
|
357
|
+
else if (kind === ContentKind_1.ContentKind.SESSION) {
|
|
358
|
+
return new Session_1.Session(doc, shouldAcquire, shareSync);
|
|
359
|
+
}
|
|
360
|
+
else if (kind === ContentKind_1.ContentKind.TERM) {
|
|
361
|
+
return new models_1.Term(doc, shouldAcquire, shareSync);
|
|
362
|
+
}
|
|
363
|
+
else if (kind === ContentKind_1.ContentKind.USER) {
|
|
364
|
+
return new User_1.User(doc, shouldAcquire, shareSync);
|
|
365
|
+
}
|
|
366
|
+
else if (kind === ContentKind_1.ContentKind.WORKSPACE) {
|
|
367
|
+
return new models_1.Workspace(doc, shouldAcquire, shareSync);
|
|
368
|
+
}
|
|
350
369
|
throw new Error(`can't wrap content ${kind}/${doc.id}`);
|
|
351
370
|
}
|
|
352
371
|
}
|