Initial docs (#61)
Add initial documentation site. Co-authored-by: ambiguous48 <33713262+ambiguous48@users.noreply.github.com>
This commit is contained in:
24
src/lib/utils/run-with-cleanup.ts
Normal file
24
src/lib/utils/run-with-cleanup.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
import { onDestroy } from "svelte";
|
||||
|
||||
export function createRunWithCleanup() {
|
||||
let cleanup: { [key: string]: () => any } = {};
|
||||
|
||||
onDestroy(() => {
|
||||
for (const id in cleanup) {
|
||||
cleanup[id]();
|
||||
delete cleanup[id];
|
||||
}
|
||||
})
|
||||
|
||||
return (fn: () => any, id: string) => {
|
||||
if (cleanup[id]) {
|
||||
cleanup[id]();
|
||||
delete cleanup[id];
|
||||
}
|
||||
|
||||
const result = fn();
|
||||
if (typeof result === "function") {
|
||||
cleanup[id] = result;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user