-
Notifications
You must be signed in to change notification settings - Fork 31
/
Copy pathcommon.ts
23 lines (19 loc) · 895 Bytes
/
common.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import { HMSStatsStore, HMSStore } from '../schema';
export type StoreTypes = HMSStore | HMSStatsStore;
type byIDSelector<S extends StoreTypes, T> = (store: S, id?: string) => T;
/**
* StoreSelector is a function that takes in {@link HMSStore} as argument
* and returns a part of the store that is queried using the selector.
* @typeParam T Part of the store that you wish to query.
*/
export type StoreSelector<S extends StoreTypes, T> = (store: S) => T;
/**
* takes in a normal selector which has store and id as input and curries it to make it easier to use.
* Before: store.getState((store) => normalSelector(store, peerID))
* After: store.getState(curriedSelector(peerID))
*/
export function byIDCurry<S extends StoreTypes, T>(selector: byIDSelector<S, T>): (id?: string) => StoreSelector<S, T> {
return (id?: string) => {
return (store: S) => selector(store, id);
};
}