Skip to content

Commit 0ca593b

Browse files
committed
fix: beef up subscription update method
1 parent ee76345 commit 0ca593b

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

site/src/hooks/useTimeSync.tsx

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -171,13 +171,25 @@ export class TimeSync implements TimeSyncApi {
171171
this.#latestDateSnapshot = this.#createNewDatetime(
172172
this.#latestDateSnapshot,
173173
);
174-
this.#notifySubscriptions();
174+
this.#flushUpdateToSubscriptions();
175175
}, newFastestInterval);
176176
}
177177

178-
#notifySubscriptions(): void {
178+
#flushUpdateToSubscriptions(): void {
179179
for (const subEntry of this.#subscriptions) {
180-
subEntry.onUpdate(this.#latestDateSnapshot);
180+
if (subEntry.select === undefined) {
181+
subEntry.onUpdate(this.#latestDateSnapshot);
182+
continue;
183+
}
184+
185+
// Keeping things simple by only comparing values React-style with ===.
186+
// If that becomes a problem down the line, we can beef the class up
187+
const prevSelection = this.#selectionCache.get(subEntry.id);
188+
const newSelection = subEntry.select(this.#latestDateSnapshot);
189+
if (prevSelection !== newSelection) {
190+
this.#selectionCache.set(subEntry.id, newSelection);
191+
subEntry.onUpdate(this.#latestDateSnapshot);
192+
}
181193
}
182194
}
183195

0 commit comments

Comments
 (0)