Skip to content

Commit 61e0ed1

Browse files
refactor(web): observe preview tests through the live registry
1 parent a98dad7 commit 61e0ed1

2 files changed

Lines changed: 2 additions & 15 deletions

File tree

‎apps/web/src/previewStateStore.test.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ import {
1919
reconcilePreviewServerSessions,
2020
rememberPreviewUrl,
2121
resetPreviewStateForTests,
22-
subscribeThreadPreviewState,
2322
setActivePreviewTab,
2423
updatePreviewServerSnapshot,
2524
} from "./previewStateStore";
25+
import { appAtomRegistry } from "./rpc/atomRegistry";
2626

2727
const environmentId = "env-1" as EnvironmentId;
2828
const ref = scopeThreadRef(environmentId, ThreadId.make("thread-1"));
@@ -352,7 +352,7 @@ describe("previewStateStore (single-tab)", () => {
352352
},
353353
};
354354
let updateCount = 0;
355-
const unsubscribe = subscribeThreadPreviewState(ref, () => {
355+
const unsubscribe = appAtomRegistry.subscribe(previewStateAtom(scopedThreadKey(ref)), () => {
356356
updateCount += 1;
357357
});
358358

‎apps/web/src/previewStateStore.ts‎

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -173,19 +173,6 @@ export function readThreadPreviewState(ref: ScopedThreadRef): ThreadPreviewState
173173
return appAtomRegistry.get(previewStateAtom(scopedThreadKey(ref)));
174174
}
175175

176-
export function subscribeThreadPreviewState(
177-
ref: ScopedThreadRef,
178-
listener: (state: ThreadPreviewState, previous: ThreadPreviewState) => void,
179-
): () => void {
180-
const atom = previewStateAtom(scopedThreadKey(ref));
181-
let previous = appAtomRegistry.get(atom);
182-
return appAtomRegistry.subscribe(atom, (state) => {
183-
const prior = previous;
184-
previous = state;
185-
listener(state, prior);
186-
});
187-
}
188-
189176
export function applyPreviewServerEvent(ref: ScopedThreadRef, event: PreviewEvent): void {
190177
updateThreadPreviewState(ref, (current) => {
191178
if (current.serverEpoch !== null && event.serverEpoch !== current.serverEpoch) return current;

0 commit comments

Comments
 (0)