mirror of
https://github.com/gitbutlerapp/gitbutler.git
synced 2024-12-02 07:53:55 +03:00
chore: nit pick some things in fetchSignal.ts
This commit is contained in:
parent
05f9fa60a9
commit
b663c40423
@ -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);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user