Fix git status polling keys and pending snapshots
- Keep remote pollers keyed by the original cwd - Initialize new cwd snapshots as pending in the web state
This commit is contained in:
1 parent
2c200cee78
commit
e234ed097c
3 files changed
+23
-12
No files matched your search
@@ -222,23 +222,22 @@ export const GitStatusBroadcasterLive = Layer.effect(
|
||||
};
|
||||
|
||||
const retainRemotePoller = Effect.fn("retainRemotePoller")(function* (cwd: string) {
|
||||
const normalizedCwd = normalizeCwd(cwd);
|
||||
yield* SynchronizedRef.modifyEffect(pollersRef, (activePollers) => {
|
||||
const existing = activePollers.get(normalizedCwd);
|
||||
const existing = activePollers.get(cwd);
|
||||
if (existing) {
|
||||
const nextPollers = new Map(activePollers);
|
||||
nextPollers.set(normalizedCwd, {
|
||||
nextPollers.set(cwd, {
|
||||
...existing,
|
||||
subscriberCount: existing.subscriberCount + 1,
|
||||
});
|
||||
return Effect.succeed([undefined, nextPollers] as const);
|
||||
}
|
||||
|
||||
return makeRemoteRefreshLoop(normalizedCwd).pipe(
|
||||
return makeRemoteRefreshLoop(cwd).pipe(
|
||||
Effect.forkIn(broadcasterScope),
|
||||
Effect.map((fiber) => {
|
||||
const nextPollers = new Map(activePollers);
|
||||
nextPollers.set(normalizedCwd, {
|
||||
nextPollers.set(cwd, {
|
||||
fiber,
|
||||
subscriberCount: 1,
|
||||
});
|
||||
@@ -249,16 +248,15 @@ export const GitStatusBroadcasterLive = Layer.effect(
|
||||
});
|
||||
|
||||
const releaseRemotePoller = Effect.fn("releaseRemotePoller")(function* (cwd: string) {
|
||||
const normalizedCwd = normalizeCwd(cwd);
|
||||
const pollerToInterrupt = yield* SynchronizedRef.modify(pollersRef, (activePollers) => {
|
||||
const existing = activePollers.get(normalizedCwd);
|
||||
const existing = activePollers.get(cwd);
|
||||
if (!existing) {
|
||||
return [null, activePollers] as const;
|
||||
}
|
||||
|
||||
if (existing.subscriberCount > 1) {
|
||||
const nextPollers = new Map(activePollers);
|
||||
nextPollers.set(normalizedCwd, {
|
||||
nextPollers.set(cwd, {
|
||||
...existing,
|
||||
subscriberCount: existing.subscriberCount - 1,
|
||||
});
|
||||
@@ -266,7 +264,7 @@ export const GitStatusBroadcasterLive = Layer.effect(
|
||||
}
|
||||
|
||||
const nextPollers = new Map(activePollers);
|
||||
nextPollers.delete(normalizedCwd);
|
||||
nextPollers.delete(cwd);
|
||||
return [existing.fiber, nextPollers] as const;
|
||||
});
|
||||
|
||||
|
||||
@@ -54,6 +54,15 @@ afterEach(() => {
|
||||
});
|
||||
|
||||
describe("gitStatusState", () => {
|
||||
it("starts fresh cwd state in a pending state", () => {
|
||||
expect(getGitStatusSnapshot("/fresh")).toEqual({
|
||||
data: null,
|
||||
error: null,
|
||||
cause: null,
|
||||
isPending: true,
|
||||
});
|
||||
});
|
||||
|
||||
it("shares one live subscription per cwd and updates the per-cwd atom snapshot", () => {
|
||||
const releaseA = watchGitStatus("/repo", gitClient);
|
||||
const releaseB = watchGitStatus("/repo", gitClient);
|
||||
|
||||
@@ -29,6 +29,10 @@ const EMPTY_GIT_STATUS_STATE = Object.freeze<GitStatusState>({
|
||||
cause: null,
|
||||
isPending: false,
|
||||
});
|
||||
const INITIAL_GIT_STATUS_STATE = Object.freeze<GitStatusState>({
|
||||
...EMPTY_GIT_STATUS_STATE,
|
||||
isPending: true,
|
||||
});
|
||||
const EMPTY_GIT_STATUS_ATOM = Atom.make(EMPTY_GIT_STATUS_STATE).pipe(
|
||||
Atom.keepAlive,
|
||||
Atom.withLabel("git-status:null"),
|
||||
@@ -46,7 +50,7 @@ let sharedGitStatusClient: GitStatusClient | null = null;
|
||||
|
||||
const gitStatusStateAtom = Atom.family((cwd: string) => {
|
||||
knownGitStatusCwds.add(cwd);
|
||||
return Atom.make(EMPTY_GIT_STATUS_STATE).pipe(
|
||||
return Atom.make(INITIAL_GIT_STATUS_STATE).pipe(
|
||||
Atom.keepAlive,
|
||||
Atom.withLabel(`git-status:${cwd}`),
|
||||
);
|
||||
@@ -122,7 +126,7 @@ export function resetGitStatusStateForTests(): void {
|
||||
sharedGitStatusClient = null;
|
||||
|
||||
for (const cwd of knownGitStatusCwds) {
|
||||
appAtomRegistry.set(gitStatusStateAtom(cwd), EMPTY_GIT_STATUS_STATE);
|
||||
appAtomRegistry.set(gitStatusStateAtom(cwd), INITIAL_GIT_STATUS_STATE);
|
||||
}
|
||||
knownGitStatusCwds.clear();
|
||||
}
|
||||
@@ -198,7 +202,7 @@ function markGitStatusPending(cwd: string): void {
|
||||
const current = appAtomRegistry.get(atom);
|
||||
const next =
|
||||
current.data === null
|
||||
? { ...EMPTY_GIT_STATUS_STATE, isPending: true }
|
||||
? INITIAL_GIT_STATUS_STATE
|
||||
: {
|
||||
...current,
|
||||
error: null,
|
||||
|
||||
Reference in new issue
Block a user