Files
subtracks/app/util/state.ts
austinried a279a81d06 Revert "remove thumbnail cache"
This reverts commit e0db4931f1.
2022-03-22 20:39:50 +09:00

18 lines
517 B
TypeScript

import { ById } from '@app/models/state'
import merge from 'lodash.merge'
export function reduceById<T extends { id: string }>(collection: T[]): ById<T> {
return collection.reduce((acc, value) => {
acc[value.id] = value
return acc
}, {} as ById<T>)
}
export function mergeById<T extends { [id: string]: unknown }>(object: T, source: T): void {
merge(object, source)
}
export function mapById<T>(object: ById<T>, ids: string[]): T[] {
return ids.map(id => object[id]).filter(a => a !== undefined)
}