Refactor away random.ts

Removed unused/duplicate methods and moved unsubscribe() to a better named file
This commit is contained in:
Caleb Owens 2024-03-20 21:08:03 +00:00
parent 7fbdfae1c4
commit b3699e2b5a
5 changed files with 10 additions and 22 deletions

View File

@ -8,7 +8,7 @@
import { persisted } from '$lib/persisted/persisted'; import { persisted } from '$lib/persisted/persisted';
import { SETTINGS_CONTEXT, type SettingsStore } from '$lib/settings/userSettings'; import { SETTINGS_CONTEXT, type SettingsStore } from '$lib/settings/userSettings';
import * as hotkeys from '$lib/utils/hotkeys'; 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 { platform } from '@tauri-apps/api/os';
import { from } from 'rxjs'; import { from } from 'rxjs';
import { onMount } from 'svelte'; import { onMount } from 'svelte';

View File

@ -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()));
};
}

View 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()));
};
}

View File

@ -15,8 +15,8 @@
import { UserService } from '$lib/stores/user'; import { UserService } from '$lib/stores/user';
import * as events from '$lib/utils/events'; import * as events from '$lib/utils/events';
import * as hotkeys from '$lib/utils/hotkeys'; import * as hotkeys from '$lib/utils/hotkeys';
import { unsubscribe } from '$lib/utils/random';
import { initTheme } from '$lib/utils/theme'; import { initTheme } from '$lib/utils/theme';
import { unsubscribe } from '$lib/utils/unsubscribe';
import { onMount, setContext } from 'svelte'; import { onMount, setContext } from 'svelte';
import { Toaster } from 'svelte-french-toast'; import { Toaster } from 'svelte-french-toast';
import type { LayoutData } from './$types'; import type { LayoutData } from './$types';

View File

@ -7,7 +7,7 @@
import ProblemLoadingRepo from '$lib/components/ProblemLoadingRepo.svelte'; import ProblemLoadingRepo from '$lib/components/ProblemLoadingRepo.svelte';
import { subscribe as menuSubscribe } from '$lib/menu'; import { subscribe as menuSubscribe } from '$lib/menu';
import * as hotkeys from '$lib/utils/hotkeys'; 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 { BranchController } from '$lib/vbranches/branchController';
import { BaseBranchService } from '$lib/vbranches/branchStoresCache'; import { BaseBranchService } from '$lib/vbranches/branchStoresCache';
import { BaseBranch } from '$lib/vbranches/types'; import { BaseBranch } from '$lib/vbranches/types';