velocious 1.0.635 → 1.0.636

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/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "velocious": "build/bin/velocious.js"
4
4
  },
5
5
  "name": "velocious",
6
- "version": "1.0.635",
6
+ "version": "1.0.636",
7
7
  "main": "build/index.js",
8
8
  "types": "build/index.d.ts",
9
9
  "files": [
@@ -1554,6 +1554,30 @@ class FrontendModelEventSubscription {
1554
1554
  return JSON.stringify(this.subscriptionParams())
1555
1555
  }
1556
1556
 
1557
+ /**
1558
+ * Runs register class callback.
1559
+ * @template {FrontendModelModelEventCallbackEntry | FrontendModelDestroyEventCallbackEntry} T
1560
+ * @param {Set<T>} callbacks - Callback set for the event type.
1561
+ * @param {T} entry - Callback entry.
1562
+ * @returns {Promise<() => void>} - Unsubscribe callback.
1563
+ */
1564
+ async registerClassCallback(callbacks, entry) {
1565
+ callbacks.add(entry)
1566
+
1567
+ try {
1568
+ await this.ensureSubscribed()
1569
+ } catch (error) {
1570
+ callbacks.delete(entry)
1571
+ this.maybeTeardown()
1572
+ throw error
1573
+ }
1574
+
1575
+ return () => {
1576
+ callbacks.delete(entry)
1577
+ this.maybeTeardown()
1578
+ }
1579
+ }
1580
+
1557
1581
  /**
1558
1582
  * Runs ensure subscribed.
1559
1583
  * @returns {Promise<void>} */
@@ -1599,14 +1623,6 @@ class FrontendModelEventSubscription {
1599
1623
  this.readyPromise = null
1600
1624
  this.subscriptionParamsKey = null
1601
1625
  this.instanceListeners.clear()
1602
-
1603
- const hasCallbacks = this.classCreateCallbacks.size > 0
1604
- || this.classUpdateCallbacks.size > 0
1605
- || this.classDestroyCallbacks.size > 0
1606
-
1607
- if (hasCallbacks && client.autoReconnect) {
1608
- void this.ensureSubscribed()
1609
- }
1610
1626
  }
1611
1627
  })
1612
1628
  await this.channelHandle.ready
@@ -3710,13 +3726,7 @@ export default class FrontendModelBase {
3710
3726
  const sub = ensureFrontendModelEventSubscription(this, frontendModelRequestContext())
3711
3727
  const entry = {callback, ...frontendModelEventOptionsPayload(this, options)}
3712
3728
 
3713
- sub.classCreateCallbacks.add(entry)
3714
- await sub.ensureSubscribed()
3715
-
3716
- return () => {
3717
- sub.classCreateCallbacks.delete(entry)
3718
- sub.maybeTeardown()
3719
- }
3729
+ return await sub.registerClassCallback(sub.classCreateCallbacks, entry)
3720
3730
  }
3721
3731
 
3722
3732
  /**
@@ -3730,13 +3740,7 @@ export default class FrontendModelBase {
3730
3740
  const sub = ensureFrontendModelEventSubscription(this, frontendModelRequestContext())
3731
3741
  const entry = {callback, ...frontendModelEventOptionsPayload(this, options)}
3732
3742
 
3733
- sub.classUpdateCallbacks.add(entry)
3734
- await sub.ensureSubscribed()
3735
-
3736
- return () => {
3737
- sub.classUpdateCallbacks.delete(entry)
3738
- sub.maybeTeardown()
3739
- }
3743
+ return await sub.registerClassCallback(sub.classUpdateCallbacks, entry)
3740
3744
  }
3741
3745
 
3742
3746
  /**
@@ -3752,13 +3756,7 @@ export default class FrontendModelBase {
3752
3756
  const sub = ensureFrontendModelEventSubscription(this, frontendModelRequestContext())
3753
3757
  const entry = {callback}
3754
3758
 
3755
- sub.classDestroyCallbacks.add(entry)
3756
- await sub.ensureSubscribed()
3757
-
3758
- return () => {
3759
- sub.classDestroyCallbacks.delete(entry)
3760
- sub.maybeTeardown()
3761
- }
3759
+ return await sub.registerClassCallback(sub.classDestroyCallbacks, entry)
3762
3760
  }
3763
3761
 
3764
3762
  /**