mirror of
https://github.com/gitbutlerapp/gitbutler.git
synced 2024-12-24 10:02:26 +03:00
Refactor away random.ts
Removed unused/duplicate methods and moved unsubscribe() to a better named file
This commit is contained in:
parent
7fbdfae1c4
commit
b3699e2b5a
@ -8,7 +8,7 @@
|
||||
import { persisted } from '$lib/persisted/persisted';
|
||||
import { SETTINGS_CONTEXT, type SettingsStore } from '$lib/settings/userSettings';
|
||||
import * as hotkeys from '$lib/utils/hotkeys';
|
||||
import { unsubscribe } from '$lib/utils/random';
|
||||
import { unsubscribe } from '$lib/utils/unsubscribe';
|
||||
import { platform } from '@tauri-apps/api/os';
|
||||
import { from } from 'rxjs';
|
||||
import { onMount } from 'svelte';
|
||||
|
@ -1,19 +0,0 @@
|
||||
export function debounce<T extends (...args: any[]) => any>(fn: T, delay: number) {
|
||||
let timeout: ReturnType<typeof setTimeout>;
|
||||
return (...args: any[]) => {
|
||||
clearTimeout(timeout);
|
||||
timeout = setTimeout(() => fn(...args), delay);
|
||||
};
|
||||
}
|
||||
|
||||
export function clone<T>(obj: T): T {
|
||||
return structuredClone(obj);
|
||||
}
|
||||
|
||||
type MaybePromise<T> = T | Promise<T>;
|
||||
|
||||
export function unsubscribe(...unsubscribers: MaybePromise<() => void>[]) {
|
||||
return () => {
|
||||
unsubscribers.forEach((unsubscriber) => Promise.resolve(unsubscriber).then((fn) => fn()));
|
||||
};
|
||||
}
|
7
gitbutler-ui/src/lib/utils/unsubscribe.ts
Normal file
7
gitbutler-ui/src/lib/utils/unsubscribe.ts
Normal file
@ -0,0 +1,7 @@
|
||||
type MaybePromise<T> = T | Promise<T>;
|
||||
|
||||
export function unsubscribe(...unsubscribers: MaybePromise<() => void>[]) {
|
||||
return () => {
|
||||
unsubscribers.forEach((unsubscriber) => Promise.resolve(unsubscriber).then((fn) => fn()));
|
||||
};
|
||||
}
|
@ -15,8 +15,8 @@
|
||||
import { UserService } from '$lib/stores/user';
|
||||
import * as events from '$lib/utils/events';
|
||||
import * as hotkeys from '$lib/utils/hotkeys';
|
||||
import { unsubscribe } from '$lib/utils/random';
|
||||
import { initTheme } from '$lib/utils/theme';
|
||||
import { unsubscribe } from '$lib/utils/unsubscribe';
|
||||
import { onMount, setContext } from 'svelte';
|
||||
import { Toaster } from 'svelte-french-toast';
|
||||
import type { LayoutData } from './$types';
|
||||
|
@ -7,7 +7,7 @@
|
||||
import ProblemLoadingRepo from '$lib/components/ProblemLoadingRepo.svelte';
|
||||
import { subscribe as menuSubscribe } from '$lib/menu';
|
||||
import * as hotkeys from '$lib/utils/hotkeys';
|
||||
import { unsubscribe } from '$lib/utils/random';
|
||||
import { unsubscribe } from '$lib/utils/unsubscribe';
|
||||
import { BranchController } from '$lib/vbranches/branchController';
|
||||
import { BaseBranchService } from '$lib/vbranches/branchStoresCache';
|
||||
import { BaseBranch } from '$lib/vbranches/types';
|
||||
|
Loading…
Reference in New Issue
Block a user