Skip to content

Commit fae9743

Browse files
committed
Clean up public API
1 parent 2261dd8 commit fae9743

File tree

3 files changed

+54
-43
lines changed

3 files changed

+54
-43
lines changed

index.d.ts

Lines changed: 53 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -9,63 +9,78 @@ declare namespace 'ng2-redux-form' {
99
export const provideFormConnect: <T>(arg: Store<T> | NgRedux<T>) => Provider[];
1010

1111
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;
1414

1515
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;
3129
}
3230

3331
export class FormException extends Error {}
3432

3533
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;
3836

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.
3942
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;
4445

45-
export const FORM_CHANGED: string;
46+
/// Get current application state
47+
getState(): RootState;
4648

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;
5351
}
5452

53+
/// This is the action dispatched when form values change.
54+
export const FORM_CHANGED: string;
55+
5556
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;
5865
}
5966

6067
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;
6269
}
6370

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.
6479
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;
7085
}
7186
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,5 +63,5 @@
6363
"typings": "rimraf typings && typings install"
6464
},
6565
"main": "dist/main.js",
66-
"typings": "dist/source/index.d.ts"
66+
"typings": "index.d.ts"
6767
}

source/connect.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,6 @@ export class Connect<RootState> {
4040
});
4141
}
4242

43-
get _parent() {
44-
return this.form;
45-
}
46-
4743
public get path(): string[] {
4844
const path = typeof this.connect === 'function'
4945
? this.connect()

0 commit comments

Comments
 (0)