@@ -9,63 +9,78 @@ declare namespace 'ng2-redux-form' {
9
9
export const provideFormConnect : < T > ( arg : Store < T > | NgRedux < T > ) => Provider [ ] ;
10
10
11
11
export function composeReducers < State > (
12
- ...reducers : ( < A extends Action > ( state : State , action : A ) => State ) [ ] ) =>
13
- < A extends Action > ( state : State , action : A ) => State ;
12
+ ...reducers : ( < A extends Action > ( state : State , action : A ) => State ) [ ] ) =>
13
+ < A extends Action > ( state : State , action : A ) => State ;
14
14
15
15
export class Connect < RootState > {
16
- private children ;
17
- private store ;
18
- private form ;
19
- connect : ( ) => ( string | string [ ] ) | string | string [ ] ;
20
- private stateSubscription ;
21
- private formSubscription ;
22
- constructor ( children : QueryList < NgControl > , store : FormStore < RootState > , form : NgForm ) ;
23
- _parent : NgForm ;
24
- path : string [ ] ;
25
- ngOnDestroy ( ) : void ;
26
- private ngAfterViewInit ( ) ;
27
- private ngAfterContentInit ( ) ;
28
- protected resetState ( ) : void ;
29
- protected publish ( value : any ) : void ;
30
- protected getState ( ) : RootState ;
16
+ /// The path to the piece of state that this form is connecting to
17
+ connect : ( ) => ( string | string [ ] ) | string | string [ ] ;
18
+
19
+ /// The control path of this directive (up to the root form)
20
+ path : string [ ] ;
21
+
22
+ constructor ( children : QueryList < NgControl > , store : FormStore < RootState > , form : NgForm ) ;
23
+
24
+ /// Update the form models with the latest state from the {@link AbstractStore }
25
+ protected resetState ( ) : void ;
26
+
27
+ /// Publish new form input values to the store
28
+ protected publish < T > ( value : T ) : void ;
31
29
}
32
30
33
31
export class FormException extends Error { }
34
32
35
33
export function defaultFormReducer < RootState > (
36
- initialState ?: RootState | Iterable . Keyed < string , any > ) =>
37
- ( state : RootState | Iterable . Keyed < string , any > , action : Redux . Action & { payload ?} ) => any;
34
+ initialState ?: RootState | Iterable . Keyed < string , any > ) =>
35
+ ( state : RootState | Iterable . Keyed < string , any > , action : Redux . Action & { payload ?} ) => any;
38
36
37
+ /// The store you provide in your call to {@link provideFormConnect } must conform to the
38
+ /// contract described by AbstractStore. Both NgRedux and redux.Store conform. If you
39
+ /// wish to supply a store that is neither an NgRedux store or a redux store, you can do
40
+ /// it as long as your custom store is the same shape as AbstractStore<RootState>. The
41
+ /// type argument of AbstractStore is your root application state interface.
39
42
export interface AbstractStore < RootState > {
40
- dispatch ( action : Action & { payload ?} ) : void ;
41
- getState ( ) : RootState ;
42
- subscribe ( fn : ( state : RootState ) => void ) : Redux . Unsubscribe ;
43
- }
43
+ /// Dispatch an action to the store
44
+ dispatch ( action : Action & { payload ?} ) : void ;
44
45
45
- export const FORM_CHANGED : string ;
46
+ /// Get current application state
47
+ getState ( ) : RootState ;
46
48
47
- export class FormStore < RootState > {
48
- private store ;
49
- constructor ( store : AbstractStore < RootState > ) ;
50
- getState ( ) : RootState ;
51
- subscribe ( fn : ( state : RootState ) => void ) : Redux . Unsubscribe ;
52
- valueChanged < T > ( path : string [ ] , form : NgForm , value : T ) : void ;
49
+ /// Subscribe to store changes
50
+ subscribe ( fn : ( state : RootState ) => void ) : Redux . Unsubscribe ;
53
51
}
54
52
53
+ /// This is the action dispatched when form values change.
54
+ export const FORM_CHANGED : string ;
55
+
55
56
export interface Operations < T > {
56
- clone ( ) : T ;
57
- update ( key : number | string , value : T ) : any ;
57
+ /// Clone this object
58
+ clone ( ) : T ;
59
+
60
+ /// Merge the contents of {@link value } with this object ({@link key} is optional)
61
+ merge ( key : number | string , value : T ) : any ;
62
+
63
+ /// Update the values of this object with {@link value }
64
+ update ( key : number | string , value : T ) : any ;
58
65
}
59
66
60
67
export interface TraverseCallback {
61
- ( parent : any , key : number | string , remainingPath : string [ ] , value ?: any ) : any ;
68
+ ( parent : any , key : number | string , remainingPath : string [ ] , value ?: any ) : any ;
62
69
}
63
70
71
+ /// Methods to extract and assign state. Use the {@link inspect } method to retrieve an
72
+ /// {@link Operations<T> } object that you can use to clone, merge or update a state
73
+ /// object. The primary feature of {@link State } is that it works with objects of any
74
+ /// type: Map, WeakMap, Set, WeakSet, ImmutableJS, and any. Your state can mix and
75
+ /// match these types in any way you like and the assign/get operations will still work.
76
+ /// You could have a Map nested inside an Immutable map nested inside of an array,
77
+ /// for example. The {@param path } argument specifies the path that will be taken when
78
+ /// doing these operations.
64
79
export abstract class State {
65
- static traverse < State > ( state : State , path : string [ ] , fn ?: TraverseCallback ) : State ;
66
- static get < State > ( state : State , path : string [ ] ) : any ;
67
- static assign < State > ( state : State , path : string [ ] , value ?: any ) : any ;
68
- static inspect < K > ( object : K ) : Operations < K > ;
69
- static empty ( value : any ) : boolean ;
80
+ static traverse < State > ( state : State , path : string [ ] , fn ?: TraverseCallback ) : State ;
81
+ static get < State > ( state : State , path : string [ ] ) : any ;
82
+ static assign < State > ( state : State , path : string [ ] , value ) : any ;
83
+ static inspect < K > ( object : K ) : Operations < K > ;
84
+ static empty ( value : any ) : boolean ;
70
85
}
71
86
}
0 commit comments