@abraca/dabra 0.4.0 → 0.6.0

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.
@@ -1994,12 +1994,16 @@ var OfflineStore = class {
1994
1994
  */
1995
1995
  constructor(docId, serverOrigin) {
1996
1996
  this.db = null;
1997
+ this.dbPromise = null;
1997
1998
  this.storeKey = serverOrigin ? `${serverOrigin}/${docId}` : docId;
1998
1999
  }
1999
- async getDb() {
2000
- if (!idbAvailable()) return null;
2001
- if (!this.db) this.db = await openDb$1(this.storeKey).catch(() => null);
2002
- return this.db;
2000
+ getDb() {
2001
+ if (!idbAvailable()) return Promise.resolve(null);
2002
+ if (!this.dbPromise) this.dbPromise = openDb$1(this.storeKey).catch(() => null).then((db) => {
2003
+ this.db = db;
2004
+ return db;
2005
+ });
2006
+ return this.dbPromise;
2003
2007
  }
2004
2008
  async persistUpdate(update) {
2005
2009
  const db = await this.getDb();
@@ -2194,9 +2198,8 @@ var AbracadabraProvider = class AbracadabraProvider extends HocuspocusProvider {
2194
2198
  */
2195
2199
  async _initFromOfflineStore() {
2196
2200
  if (!this.offlineStore) return;
2197
- const snapshot = await this.offlineStore.getDocSnapshot().catch(() => null);
2201
+ const [snapshot, pending] = await Promise.all([this.offlineStore.getDocSnapshot().catch(() => null), this.offlineStore.getPendingUpdates().catch(() => [])]);
2198
2202
  if (snapshot) Y.applyUpdate(this.document, snapshot, this.offlineStore);
2199
- const pending = await this.offlineStore.getPendingUpdates().catch(() => []);
2200
2203
  for (const update of pending) Y.applyUpdate(this.document, update, this.offlineStore);
2201
2204
  }
2202
2205
  authenticatedHandler(scope) {
@@ -2335,18 +2338,7 @@ var AbracadabraProvider = class AbracadabraProvider extends HocuspocusProvider {
2335
2338
  }
2336
2339
  async _doLoadChild(childId) {
2337
2340
  const childDoc = new Y.Doc({ guid: childId });
2338
- if (this.isConnected) await new Promise((resolve) => {
2339
- const onRegistered = ({ childId: cid }) => {
2340
- if (cid === childId) {
2341
- this.off("subdocRegistered", onRegistered);
2342
- resolve();
2343
- }
2344
- };
2345
- this.on("subdocRegistered", onRegistered);
2346
- this.registerSubdoc(childDoc);
2347
- setTimeout(resolve, 3e3);
2348
- });
2349
- else this.registerSubdoc(childDoc);
2341
+ this.registerSubdoc(childDoc);
2350
2342
  const childProvider = new AbracadabraProvider({
2351
2343
  name: childId,
2352
2344
  document: childDoc,