@@ -8,8 +8,6 @@ interface RootState<StatePart> {
88 [ statePart : string ] : StatePart ;
99}
1010
11- type Selector < State > = ( state : RootState < State > , ...args : any [ ] ) => any ;
12-
1311// Provide action keys for auto-complete but allow custom types
1412// that are eg. auto-generated by fetchable action
1513type ActionTypes < Actions > = { [ K in keyof Actions ] : string } & {
@@ -51,16 +49,12 @@ interface Fetchable {
5149 ) => FetchableReducers < State > ;
5250}
5351
54- interface Dependencies {
55- [ depName : string ] : Model < any , any > ;
56- }
57-
5852// TODO:
5953// Figure out how to show proper error
6054// if given action is not in keyof Actions
61- interface ModelDefinition < State , Actions , Deps > {
55+ interface ModelDefinition < State , Actions , Selectors , Deps > {
6256 name : string ;
63- inject ?: [ keyof Deps ] ;
57+ inject ?: ( keyof Deps ) [ ] ;
6458 state : State ;
6559 actions : (
6660 { initialState } : { initialState : State }
@@ -78,10 +72,8 @@ interface ModelDefinition<State, Actions, Deps> {
7872 [ depType : string ] : Reducer < State > ;
7973 } ;
8074 selectors ?: (
81- { name } : { name : string }
82- ) => {
83- [ selectorName : string ] : Selector < State > ;
84- } ;
75+ { name, selectors } : { name : string ; selectors : Selectors }
76+ ) => Selectors ;
8577 sagas ?: (
8678 { types, deps } : { types : ActionTypes < Actions > ; deps : Deps }
8779 ) => any [ ] ;
@@ -91,12 +83,12 @@ interface ModelDefinition<State, Actions, Deps> {
9183 } ;
9284}
9385
94- interface Model < State , Actions > {
86+ interface Model < State , Actions , Selectors > {
9587 name : string ;
9688 initialState : State ;
9789 types : ActionTypes < Actions > ;
9890 actions : Actions ;
99- selectors : {
91+ selectors : Selectors & {
10092 get : < K extends keyof State > (
10193 stateField : K
10294 ) => ( state : RootState < State > , ...args : any [ ] ) => Pick < State , K > [ K ] ;
@@ -128,17 +120,17 @@ export interface FetchableAction<SuccessData> extends ActionFunc {
128120
129121export const fetchable : Fetchable ;
130122
131- export function createModel < State , Actions , Deps = Dependencies > (
132- df : ModelDefinition < State , Actions , Deps >
133- ) : Model < State , Actions > ;
123+ export function createModel < State , Actions , Selectors = { } , Deps = { } > (
124+ df : ModelDefinition < State , Actions , Selectors , Deps >
125+ ) : Model < State , Actions , Selectors > ;
134126
135127export function initModels (
136- models : Model < any , any > [ ]
128+ models : Model < any , any , any > [ ]
137129) : {
138130 allReducers : {
139131 [ x : string ] : Reducer < any > ;
140132 } ;
141133 allSagas : any [ ] ;
142134} & {
143- [ modelName : string ] : Model < any , any > ;
135+ [ modelName : string ] : Model < any , any , any > ;
144136} ;
0 commit comments