chore: nit pick some things in fetchSignal.ts

This commit is contained in:
Mattias Granlund 2024-07-15 17:11:11 +01:00
parent 05f9fa60a9
commit b663c40423

View File

@ -2,18 +2,17 @@ import { listen } from '$lib/backend/ipc';
import { readable } from 'svelte/store';
export class FetchSignal {
readonly event = readable<number>(undefined, (set) => {
const unsubscribe = subscribeToFetches(this.projectId, () => set(this.counter++));
return () => {
unsubscribe();
};
});
// Stores only emit unique values so we use a counter to ensure
// derived stores are updated.
private counter = 0;
// Emits a new value when a fetch was detected by the back end.
readonly event = readable<number>(undefined, (set) => {
const unsubscribe = listen<any>(`project://${this.projectId}/git/fetch`, () =>
set(this.counter++)
);
return async () => await unsubscribe();
});
constructor(private projectId: string) {}
}
export function subscribeToFetches(projectId: string, callback: () => Promise<void> | void) {
return listen<any>(`project://${projectId}/git/fetch`, callback);
}