1 | import { ActionReducer, Prettify, Primitive, Selector } from './models';
|
2 | import { MemoizedSelector } from './selector';
|
3 | export interface FeatureConfig<FeatureName extends string, FeatureState> {
|
4 | name: FeatureName;
|
5 | reducer: ActionReducer<FeatureState>;
|
6 | }
|
7 | type Feature<FeatureName extends string, FeatureState> = FeatureConfig<FeatureName, FeatureState> & BaseSelectors<FeatureName, FeatureState>;
|
8 | type FeatureWithExtraSelectors<FeatureName extends string, FeatureState, ExtraSelectors extends SelectorsDictionary> = string extends keyof ExtraSelectors ? Feature<FeatureName, FeatureState> : Omit<Feature<FeatureName, FeatureState>, keyof ExtraSelectors> & ExtraSelectors;
|
9 | type FeatureSelector<FeatureName extends string, FeatureState> = {
|
10 | [K in FeatureName as `select${Capitalize<K>}State`]: MemoizedSelector<Record<string, any>, FeatureState, (featureState: FeatureState) => FeatureState>;
|
11 | };
|
12 | type NestedSelectors<FeatureState> = FeatureState extends Primitive | unknown[] | Date ? {} : {
|
13 | [K in keyof FeatureState & string as `select${Capitalize<K>}`]: MemoizedSelector<Record<string, any>, FeatureState[K], (featureState: FeatureState) => FeatureState[K]>;
|
14 | };
|
15 | type BaseSelectors<FeatureName extends string, FeatureState> = FeatureSelector<FeatureName, FeatureState> & NestedSelectors<FeatureState>;
|
16 | type SelectorsDictionary = Record<string, Selector<Record<string, any>, unknown> | ((...args: any[]) => Selector<Record<string, any>, unknown>)>;
|
17 | type ExtraSelectorsFactory<FeatureName extends string, FeatureState, ExtraSelectors extends SelectorsDictionary> = (baseSelectors: BaseSelectors<FeatureName, FeatureState>) => ExtraSelectors;
|
18 | type NotAllowedFeatureStateCheck<FeatureState> = FeatureState extends Required<FeatureState> ? unknown : 'optional properties are not allowed in the feature state';
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 |
|
27 |
|
28 | export declare function createFeature<FeatureName extends string, FeatureState, ExtraSelectors extends SelectorsDictionary>(featureConfig: FeatureConfig<FeatureName, FeatureState> & {
|
29 | extraSelectors: ExtraSelectorsFactory<FeatureName, FeatureState, ExtraSelectors>;
|
30 | } & NotAllowedFeatureStateCheck<FeatureState>): Prettify<FeatureWithExtraSelectors<FeatureName, FeatureState, ExtraSelectors>>;
|
31 |
|
32 |
|
33 |
|
34 |
|
35 |
|
36 |
|
37 |
|
38 |
|
39 | export declare function createFeature<FeatureName extends string, FeatureState>(featureConfig: FeatureConfig<FeatureName, FeatureState> & NotAllowedFeatureStateCheck<FeatureState>): Prettify<Feature<FeatureName, FeatureState>>;
|
40 | export {};
|