mirror of
https://github.com/austinried/subtracks.git
synced 2026-02-10 15:02:42 +01:00
reorg, remove old music slice files
This commit is contained in:
17
app/util/state.ts
Normal file
17
app/util/state.ts
Normal file
@@ -0,0 +1,17 @@
|
||||
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)
|
||||
}
|
||||
Reference in New Issue
Block a user