Code Cleanup™
This commit is contained in:
@@ -21,7 +21,7 @@ import {readonly, writable} from "svelte/store";
|
||||
|
||||
import type {Readable, Subscriber, Unsubscriber} from "svelte/store";
|
||||
|
||||
export interface Cached<T> extends Readable<T>{
|
||||
export interface Cached<T> extends Readable<T> {
|
||||
reload: () => void;
|
||||
}
|
||||
|
||||
@@ -38,20 +38,20 @@ export function cached<T>(normal: T, init: () => Promise<T>): Cached<T> {
|
||||
return {
|
||||
...readonly(store),
|
||||
subscribe: (run: Subscriber<T>, invalidate?: (value?: T) => void): Unsubscriber => {
|
||||
if(first) {
|
||||
if (first) {
|
||||
first = false;
|
||||
reload();
|
||||
}
|
||||
return store.subscribe(run, invalidate);
|
||||
},
|
||||
reload
|
||||
reload,
|
||||
};
|
||||
}
|
||||
|
||||
export function cachedFamily<T, K>(normal: K, init: (arg0: T) => Promise<K>): (arg: T) => Cached<K> {
|
||||
const stores: Map<T, Cached<K>> = new Map();
|
||||
return (arg: T) => {
|
||||
if(stores.has(arg)) {
|
||||
if (stores.has(arg)) {
|
||||
return stores.get(arg)!;
|
||||
} else {
|
||||
const store = writable<K>(normal);
|
||||
@@ -66,13 +66,13 @@ export function cachedFamily<T, K>(normal: K, init: (arg0: T) => Promise<K>): (a
|
||||
const cachedStore = {
|
||||
...readonly(store),
|
||||
subscribe: (run: Subscriber<K>, invalidate?: (value?: K) => void): Unsubscriber => {
|
||||
if(first) {
|
||||
if (first) {
|
||||
first = false;
|
||||
reload();
|
||||
}
|
||||
return store.subscribe(run, invalidate);
|
||||
},
|
||||
reload
|
||||
reload,
|
||||
} as Cached<K>;
|
||||
|
||||
stores.set(arg, cachedStore);
|
||||
|
||||
Reference in New Issue
Block a user