@abraca/dabra 0.5.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.
@@ -2024,12 +2024,16 @@ var OfflineStore = class {
2024
2024
  */
2025
2025
  constructor(docId, serverOrigin) {
2026
2026
  this.db = null;
2027
+ this.dbPromise = null;
2027
2028
  this.storeKey = serverOrigin ? `${serverOrigin}/${docId}` : docId;
2028
2029
  }
2029
- async getDb() {
2030
- if (!idbAvailable()) return null;
2031
- if (!this.db) this.db = await openDb$1(this.storeKey).catch(() => null);
2032
- return this.db;
2030
+ getDb() {
2031
+ if (!idbAvailable()) return Promise.resolve(null);
2032
+ if (!this.dbPromise) this.dbPromise = openDb$1(this.storeKey).catch(() => null).then((db) => {
2033
+ this.db = db;
2034
+ return db;
2035
+ });
2036
+ return this.dbPromise;
2033
2037
  }
2034
2038
  async persistUpdate(update) {
2035
2039
  const db = await this.getDb();
@@ -2224,9 +2228,8 @@ var AbracadabraProvider = class AbracadabraProvider extends HocuspocusProvider {
2224
2228
  */
2225
2229
  async _initFromOfflineStore() {
2226
2230
  if (!this.offlineStore) return;
2227
- const snapshot = await this.offlineStore.getDocSnapshot().catch(() => null);
2231
+ const [snapshot, pending] = await Promise.all([this.offlineStore.getDocSnapshot().catch(() => null), this.offlineStore.getPendingUpdates().catch(() => [])]);
2228
2232
  if (snapshot) yjs.applyUpdate(this.document, snapshot, this.offlineStore);
2229
- const pending = await this.offlineStore.getPendingUpdates().catch(() => []);
2230
2233
  for (const update of pending) yjs.applyUpdate(this.document, update, this.offlineStore);
2231
2234
  }
2232
2235
  authenticatedHandler(scope) {
@@ -2365,18 +2368,7 @@ var AbracadabraProvider = class AbracadabraProvider extends HocuspocusProvider {
2365
2368
  }
2366
2369
  async _doLoadChild(childId) {
2367
2370
  const childDoc = new yjs.Doc({ guid: childId });
2368
- if (this.isConnected) await new Promise((resolve) => {
2369
- const onRegistered = ({ childId: cid }) => {
2370
- if (cid === childId) {
2371
- this.off("subdocRegistered", onRegistered);
2372
- resolve();
2373
- }
2374
- };
2375
- this.on("subdocRegistered", onRegistered);
2376
- this.registerSubdoc(childDoc);
2377
- setTimeout(resolve, 3e3);
2378
- });
2379
- else this.registerSubdoc(childDoc);
2371
+ this.registerSubdoc(childDoc);
2380
2372
  const childProvider = new AbracadabraProvider({
2381
2373
  name: childId,
2382
2374
  document: childDoc,