Memoize some stores, improve room support
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import {readable, derived, writable, Readable, Subscriber} from "svelte/store"
|
||||
import {batch, indexBy, remove, assoc, now} from "@welshman/lib"
|
||||
import {withGetter, ReadableWithGetter} from "./getter.js"
|
||||
import {memoized} from "./memoize.js"
|
||||
|
||||
// Collection utility
|
||||
|
||||
@@ -126,7 +127,7 @@ export const collection = <T>({name, store, getKey, load}: CollectionOptions<T>)
|
||||
// store will update when it arrives
|
||||
loadItem(key, relays)
|
||||
|
||||
return derived(indexStore, $index => $index.get(key))
|
||||
return memoized<T | undefined>(derived(indexStore, $index => $index.get(key)))
|
||||
}
|
||||
|
||||
const onItem = (cb: Subscriber<T>) => {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
export * from "./synced.js"
|
||||
export * from "./getter.js"
|
||||
export * from "./throttle.js"
|
||||
export * from "./memoize.js"
|
||||
export * from "./custom.js"
|
||||
export * from "./repository.js"
|
||||
export * from "./collection.js"
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
import {Readable, Subscriber} from "svelte/store"
|
||||
import {memoize} from "@welshman/lib"
|
||||
|
||||
export const memoized = <T>(store: Readable<T>) => {
|
||||
const {subscribe} = store
|
||||
|
||||
return {...store, subscribe: (f: Subscriber<T>) => subscribe(memoize(f))}
|
||||
}
|
||||
Reference in New Issue
Block a user