Skip to content

Commit a7be158

Browse files
refactor(store): bump dgeni and move models back to creator files (#3887)
1 parent 634fdcb commit a7be158

File tree

6 files changed

+123
-141
lines changed

6 files changed

+123
-141
lines changed

modules/store/src/action_group_creator.ts

Lines changed: 91 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,96 @@
11
import { createAction, props } from './action_creator';
2-
import { ActionCreatorProps, Creator } from './models';
3-
import { capitalize, uncapitalize } from './helpers';
42
import {
5-
ActionGroup,
6-
ActionGroupConfig,
7-
ActionName,
8-
} from './action_group_creator_models';
3+
ActionCreator,
4+
ActionCreatorProps,
5+
Creator,
6+
FunctionWithParametersType,
7+
NotAllowedCheck,
8+
TypedAction,
9+
} from './models';
10+
import { capitalize, uncapitalize } from './helpers';
11+
12+
type Join<
13+
Str extends string,
14+
Separator extends string = ' '
15+
> = Str extends `${infer First}${Separator}${infer Rest}`
16+
? Join<`${First}${Rest}`, Separator>
17+
: Str;
18+
19+
type CapitalizeWords<Str extends string> =
20+
Str extends `${infer First} ${infer Rest}`
21+
? `${Capitalize<First>} ${CapitalizeWords<Rest>}`
22+
: Capitalize<Str>;
23+
24+
type StringLiteralCheck<
25+
Str extends string,
26+
Name extends string
27+
> = string extends Str ? `${Name} must be a string literal type` : unknown;
28+
29+
type UniqueEventNameCheck<
30+
EventNames extends string,
31+
EventName extends string
32+
> = ActionName<EventName> extends ActionName<Exclude<EventNames, EventName>>
33+
? `${ActionName<EventName>} action is already defined`
34+
: unknown;
35+
36+
type NotAllowedEventPropsCheck<
37+
PropsCreator extends ActionCreatorProps<unknown> | Creator
38+
> = PropsCreator extends ActionCreatorProps<infer Props>
39+
? Props extends void
40+
? unknown
41+
: NotAllowedCheck<Props & object>
42+
: PropsCreator extends Creator<any, infer Result>
43+
? NotAllowedCheck<Result>
44+
: unknown;
45+
46+
type EventCreator<
47+
PropsCreator extends ActionCreatorProps<unknown> | Creator,
48+
Type extends string
49+
> = PropsCreator extends ActionCreatorProps<infer Props>
50+
? void extends Props
51+
? ActionCreator<Type, () => TypedAction<Type>>
52+
: ActionCreator<
53+
Type,
54+
(
55+
props: Props & NotAllowedCheck<Props & object>
56+
) => Props & TypedAction<Type>
57+
>
58+
: PropsCreator extends Creator<infer Props, infer Result>
59+
? FunctionWithParametersType<
60+
Props,
61+
Result & NotAllowedCheck<Result> & TypedAction<Type>
62+
> &
63+
TypedAction<Type>
64+
: never;
65+
66+
type ActionName<EventName extends string> = Uncapitalize<
67+
Join<CapitalizeWords<EventName>>
68+
>;
69+
70+
interface ActionGroupConfig<
71+
Source extends string,
72+
Events extends Record<string, ActionCreatorProps<unknown> | Creator>
73+
> {
74+
source: Source & StringLiteralCheck<Source, 'source'>;
75+
events: Events & {
76+
[EventName in keyof Events]: StringLiteralCheck<
77+
EventName & string,
78+
'event name'
79+
> &
80+
UniqueEventNameCheck<keyof Events & string, EventName & string> &
81+
NotAllowedEventPropsCheck<Events[EventName]>;
82+
};
83+
}
84+
85+
type ActionGroup<
86+
Source extends string,
87+
Events extends Record<string, ActionCreatorProps<unknown> | Creator>
88+
> = {
89+
[EventName in keyof Events as ActionName<EventName & string>]: EventCreator<
90+
Events[EventName],
91+
`[${Source}] ${EventName & string}`
92+
>;
93+
};
994

1095
/**
1196
* @description

modules/store/src/action_group_creator_models.ts

Lines changed: 0 additions & 95 deletions
This file was deleted.

modules/store/src/feature_creator.ts

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
import { capitalize } from './helpers';
2-
import { ActionReducer, Selector } from './models';
2+
import { ActionReducer, Primitive, Selector } from './models';
33
import { isPlainObject } from './meta-reducers/utils';
44
import {
55
createFeatureSelector,
66
createSelector,
77
MemoizedSelector,
88
} from './selector';
9-
import { FeatureSelector, NestedSelectors } from './feature_creator_models';
109

1110
export interface FeatureConfig<FeatureName extends string, FeatureState> {
1211
name: FeatureName;
@@ -32,6 +31,32 @@ type FeatureWithExtraSelectors<
3231
> &
3332
ExtraSelectors;
3433

34+
type FeatureSelector<
35+
AppState extends Record<string, any>,
36+
FeatureName extends keyof AppState & string,
37+
FeatureState extends AppState[FeatureName]
38+
> = {
39+
[K in FeatureName as `select${Capitalize<K>}State`]: MemoizedSelector<
40+
AppState,
41+
FeatureState,
42+
(featureState: FeatureState) => FeatureState
43+
>;
44+
};
45+
46+
type NestedSelectors<
47+
AppState extends Record<string, any>,
48+
FeatureState
49+
> = FeatureState extends Primitive | unknown[] | Date
50+
? {}
51+
: {
52+
[K in keyof FeatureState &
53+
string as `select${Capitalize<K>}`]: MemoizedSelector<
54+
AppState,
55+
FeatureState[K],
56+
(featureState: FeatureState) => FeatureState[K]
57+
>;
58+
};
59+
3560
type BaseSelectors<
3661
AppState extends Record<string, any>,
3762
FeatureName extends keyof AppState & string,

modules/store/src/feature_creator_models.ts

Lines changed: 0 additions & 33 deletions
This file was deleted.

projects/ngrx.io/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@
109109
"cross-spawn": "^5.1.0",
110110
"css-selector-parser": "^1.3.0",
111111
"dgeni": "^0.4.14",
112-
"dgeni-packages": "^0.29.2",
112+
"dgeni-packages": "^0.30.0",
113113
"entities": "^1.1.1",
114114
"eslint": "^3.19.0",
115115
"eslint-plugin-jasmine": "^2.2.0",

projects/ngrx.io/yarn.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5858,10 +5858,10 @@ detect-node@^2.0.4:
58585858
resolved "https://registry.yarnpkg.com/detect-node/-/detect-node-2.1.0.tgz#c9c70775a49c3d03bc2c06d9a73be550f978f8b1"
58595859
integrity sha512-T0NIuQpnTvFDATNuHN5roPwSBG83rFsuO+MXXH9/3N1eFbn4wcPjttvjMLEPWJ0RGUYgQE7cGgS3tNxbqCGM7g==
58605860

5861-
dgeni-packages@^0.29.2:
5862-
version "0.29.5"
5863-
resolved "https://registry.yarnpkg.com/dgeni-packages/-/dgeni-packages-0.29.5.tgz#6e94ec4b343fa3b1bdd517dbdee05166a05b10ef"
5864-
integrity sha512-jKwWNA10+p/TDKPEFnsbeRQ027CpmM+cWhh3Fp8dRI+2e2FkedoccPiQhoG5/kzheQFxcsMGB6/h63OXYNdz0A==
5861+
dgeni-packages@^0.30.0:
5862+
version "0.30.0"
5863+
resolved "https://registry.yarnpkg.com/dgeni-packages/-/dgeni-packages-0.30.0.tgz#7e8002ee154fed7bc97841222e0f25628cf2285d"
5864+
integrity sha512-k5y9HSwJzWgc8S7bHxejojJfuo2heltY9lTa5UgfqoBv2vubCwqXhVxFBXr3nKfymc9YOALCnk10JYeOdVLLWQ==
58655865
dependencies:
58665866
canonical-path "^1.0.0"
58675867
catharsis "^0.8.1"

0 commit comments

Comments
 (0)