refactor(web): observe preview tests through the live registry (#10064)
This commit is contained in:
1 parent
160e337a5c
commit
43700b83e7
2 files changed
+2
-15
No files matched your search
@@ -19,10 +19,10 @@ import {
|
||||
reconcilePreviewServerSessions,
|
||||
rememberPreviewUrl,
|
||||
resetPreviewStateForTests,
|
||||
subscribeThreadPreviewState,
|
||||
setActivePreviewTab,
|
||||
updatePreviewServerSnapshot,
|
||||
} from "./previewStateStore";
|
||||
import { appAtomRegistry } from "./rpc/atomRegistry";
|
||||
|
||||
const environmentId = "env-1" as EnvironmentId;
|
||||
const ref = scopeThreadRef(environmentId, ThreadId.make("thread-1"));
|
||||
@@ -352,7 +352,7 @@ describe("previewStateStore (single-tab)", () => {
|
||||
},
|
||||
};
|
||||
let updateCount = 0;
|
||||
const unsubscribe = subscribeThreadPreviewState(ref, () => {
|
||||
const unsubscribe = appAtomRegistry.subscribe(previewStateAtom(scopedThreadKey(ref)), () => {
|
||||
updateCount += 1;
|
||||
});
|
||||
|
||||
|
||||
@@ -173,19 +173,6 @@ export function readThreadPreviewState(ref: ScopedThreadRef): ThreadPreviewState
|
||||
return appAtomRegistry.get(previewStateAtom(scopedThreadKey(ref)));
|
||||
}
|
||||
|
||||
export function subscribeThreadPreviewState(
|
||||
ref: ScopedThreadRef,
|
||||
listener: (state: ThreadPreviewState, previous: ThreadPreviewState) => void,
|
||||
): () => void {
|
||||
const atom = previewStateAtom(scopedThreadKey(ref));
|
||||
let previous = appAtomRegistry.get(atom);
|
||||
return appAtomRegistry.subscribe(atom, (state) => {
|
||||
const prior = previous;
|
||||
previous = state;
|
||||
listener(state, prior);
|
||||
});
|
||||
}
|
||||
|
||||
export function applyPreviewServerEvent(ref: ScopedThreadRef, event: PreviewEvent): void {
|
||||
updateThreadPreviewState(ref, (current) => {
|
||||
if (current.serverEpoch !== null && event.serverEpoch !== current.serverEpoch) return current;
|
||||
|
||||
Reference in new issue
Block a user