Skip to content

Commit cd9b192

Browse files
committed
Annotate createDispatcher and composeStores
1 parent f2b37cd commit cd9b192

File tree

2 files changed

+22
-8
lines changed

2 files changed

+22
-8
lines changed

src/createDispatcher.js

+15-5
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,25 @@
1+
/* @flow */
2+
13
import compose from './utils/composeMiddleware';
24

3-
export default function createDispatcher(store, middlewares = []) {
4-
return function dispatcher(initialState, setState) {
5-
let state = setState(store(initialState, {}));
5+
import { Middleware, Store, Action, State, Dispatcher } from './types';
6+
7+
export default function createDispatcher(
8+
store: Store,
9+
middlewares: (Middleware[] | (getState: () => State) => Middleware[]) = []
10+
): Dispatcher {
11+
return function dispatcher(
12+
initialState: State,
13+
setState: (state: State) => State
14+
) {
15+
var state: State = setState(store(initialState, {}));
616

7-
function dispatch(action) {
17+
function dispatch(action: Action): Action {
818
state = setState(store(state, action));
919
return action;
1020
}
1121

12-
function getState() {
22+
function getState(): State {
1323
return state;
1424
}
1525

src/utils/composeStores.js

+7-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
1+
/* @flow */
2+
13
import mapValues from 'lodash/object/mapValues';
24

3-
export default function composeStores(stores) {
4-
return function Composition(atom = {}, action) {
5+
import { Store, Action, State } from '../types';
6+
7+
export default function composeStores(stores: Store[]): Store {
8+
return function Composition(state: State = {}, action: Action) {
59
return mapValues(stores, (store, key) =>
6-
store(atom[key], action)
10+
store(state[key], action)
711
);
812
};
913
}

0 commit comments

Comments
 (0)