mirror of
https://github.com/gitbutlerapp/gitbutler.git
synced 2024-12-03 03:33:16 +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';
|
import { readable } from 'svelte/store';
|
||||||
|
|
||||||
export class FetchSignal {
|
export class FetchSignal {
|
||||||
readonly event = readable<number>(undefined, (set) => {
|
// Stores only emit unique values so we use a counter to ensure
|
||||||
const unsubscribe = subscribeToFetches(this.projectId, () => set(this.counter++));
|
// derived stores are updated.
|
||||||
return () => {
|
|
||||||
unsubscribe();
|
|
||||||
};
|
|
||||||
});
|
|
||||||
|
|
||||||
private counter = 0;
|
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) {}
|
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