@buenos-nachos/time-sync 0.2.0 → 0.3.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.
- package/CHANGELOG.md +6 -0
- package/package.json +1 -1
- package/src/TimeSync.test.ts +7 -7
- package/src/TimeSync.ts +6 -6
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# @buenos-nachos/time-sync
|
|
2
2
|
|
|
3
|
+
## 0.3.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 122f6c1: Updated `SubscriptionContext.timeSync` type to be readonly and non-nullable, and renamed `SubscriptionContext.isLive` to `SubscriptionContext.isSubscribed`.
|
|
8
|
+
|
|
3
9
|
## 0.2.0
|
|
4
10
|
|
|
5
11
|
### Breaking Changes
|
package/package.json
CHANGED
package/src/TimeSync.test.ts
CHANGED
|
@@ -131,7 +131,7 @@ describe(TimeSync, () => {
|
|
|
131
131
|
|
|
132
132
|
const expectedCtx: SubscriptionContext = {
|
|
133
133
|
unsubscribe,
|
|
134
|
-
|
|
134
|
+
isSubscribed: true,
|
|
135
135
|
timeSync: sync,
|
|
136
136
|
intervalLastFulfilledAt: dateAfter,
|
|
137
137
|
registeredAt: dateBefore,
|
|
@@ -580,10 +580,10 @@ describe(TimeSync, () => {
|
|
|
580
580
|
});
|
|
581
581
|
|
|
582
582
|
await vi.advanceTimersByTimeAsync(refreshRates.oneMinute);
|
|
583
|
-
expect(ejectedContext?.
|
|
583
|
+
expect(ejectedContext?.isSubscribed).toBe(true);
|
|
584
584
|
|
|
585
585
|
unsub();
|
|
586
|
-
expect(ejectedContext?.
|
|
586
|
+
expect(ejectedContext?.isSubscribed).toBe(false);
|
|
587
587
|
});
|
|
588
588
|
});
|
|
589
589
|
|
|
@@ -827,7 +827,7 @@ describe(TimeSync, () => {
|
|
|
827
827
|
|
|
828
828
|
await vi.advanceTimersByTimeAsync(refreshRates.oneSecond);
|
|
829
829
|
expect(ejectedContext).toEqual<SubscriptionContext>({
|
|
830
|
-
|
|
830
|
+
isSubscribed: true,
|
|
831
831
|
intervalLastFulfilledAt: null,
|
|
832
832
|
registeredAt: snapBefore,
|
|
833
833
|
targetRefreshIntervalMs: refreshRates.oneHour,
|
|
@@ -840,7 +840,7 @@ describe(TimeSync, () => {
|
|
|
840
840
|
|
|
841
841
|
const snapAfter = sync.getStateSnapshot().date;
|
|
842
842
|
expect(ejectedContext).toEqual<SubscriptionContext>({
|
|
843
|
-
|
|
843
|
+
isSubscribed: true,
|
|
844
844
|
intervalLastFulfilledAt: snapAfter,
|
|
845
845
|
registeredAt: snapBefore,
|
|
846
846
|
targetRefreshIntervalMs: refreshRates.oneHour,
|
|
@@ -1103,10 +1103,10 @@ describe(TimeSync, () => {
|
|
|
1103
1103
|
});
|
|
1104
1104
|
|
|
1105
1105
|
await vi.advanceTimersByTimeAsync(refreshRates.oneMinute);
|
|
1106
|
-
expect(ejectedContext?.
|
|
1106
|
+
expect(ejectedContext?.isSubscribed).toBe(true);
|
|
1107
1107
|
|
|
1108
1108
|
sync.clearAll();
|
|
1109
|
-
expect(ejectedContext?.
|
|
1109
|
+
expect(ejectedContext?.isSubscribed).toBe(false);
|
|
1110
1110
|
});
|
|
1111
1111
|
});
|
|
1112
1112
|
|
package/src/TimeSync.ts
CHANGED
|
@@ -167,13 +167,13 @@ export interface SubscriptionContext {
|
|
|
167
167
|
* A reference to the TimeSync instance that the subscription was registered
|
|
168
168
|
* with.
|
|
169
169
|
*/
|
|
170
|
-
timeSync: TimeSync
|
|
170
|
+
readonly timeSync: TimeSync;
|
|
171
171
|
|
|
172
172
|
/**
|
|
173
173
|
* Indicates whether the subscription is still live. Will be mutated to be
|
|
174
174
|
* false when a subscription is
|
|
175
175
|
*/
|
|
176
|
-
|
|
176
|
+
isSubscribed: boolean;
|
|
177
177
|
|
|
178
178
|
/**
|
|
179
179
|
* Indicates when the last time the subscription had its explicit interval
|
|
@@ -585,7 +585,7 @@ export class TimeSync implements TimeSyncApi {
|
|
|
585
585
|
// Have to define this as a writeable to avoid a chicken-and-the-egg
|
|
586
586
|
// problem for the unsubscribe callback
|
|
587
587
|
const context: Writeable<SubscriptionContext> = {
|
|
588
|
-
|
|
588
|
+
isSubscribed: true,
|
|
589
589
|
timeSync: this,
|
|
590
590
|
unsubscribe: noOp,
|
|
591
591
|
registeredAt: new ReadonlyDate(),
|
|
@@ -603,7 +603,7 @@ export class TimeSync implements TimeSyncApi {
|
|
|
603
603
|
const subsOnSetup = this.#subscriptions;
|
|
604
604
|
const unsubscribe = (): void => {
|
|
605
605
|
if (!subscribed || this.#subscriptions !== subsOnSetup) {
|
|
606
|
-
context.
|
|
606
|
+
context.isSubscribed = false;
|
|
607
607
|
subscribed = false;
|
|
608
608
|
return;
|
|
609
609
|
}
|
|
@@ -630,7 +630,7 @@ export class TimeSync implements TimeSyncApi {
|
|
|
630
630
|
subscriberCount: Math.max(0, this.#latestSnapshot.subscriberCount - 1),
|
|
631
631
|
});
|
|
632
632
|
|
|
633
|
-
context.
|
|
633
|
+
context.isSubscribed = false;
|
|
634
634
|
subscribed = false;
|
|
635
635
|
};
|
|
636
636
|
context.unsubscribe = unsubscribe;
|
|
@@ -672,7 +672,7 @@ export class TimeSync implements TimeSyncApi {
|
|
|
672
672
|
// one actually has much better time complexity
|
|
673
673
|
for (const subArray of this.#subscriptions.values()) {
|
|
674
674
|
for (const ctx of subArray) {
|
|
675
|
-
ctx.
|
|
675
|
+
ctx.isSubscribed = false;
|
|
676
676
|
}
|
|
677
677
|
}
|
|
678
678
|
|