You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
19 lines
644 B
19 lines
644 B
import { denormalize } from 'normalizr'
|
|
import { userSchema, groupSchema } from 'src/store/schemas'
|
|
import { AppState, Entity, EntityType } from '../types'
|
|
|
|
export const getEntityStore = (state: AppState) => state.entities
|
|
|
|
export const getEntity = <T extends Entity = Entity>(state: AppState, type: EntityType, id?: string) => {
|
|
if (!id) return
|
|
const entities = getEntityStore(state)
|
|
|
|
switch (type) {
|
|
case EntityType.User:
|
|
return denormalize(id, userSchema, entities) as T
|
|
case EntityType.Group:
|
|
return denormalize(id, groupSchema, entities) as T
|
|
default:
|
|
return
|
|
}
|
|
}
|