Skip to content

Commit

Permalink
Annotate createDispatcher and composeStores
Browse files Browse the repository at this point in the history
  • Loading branch information
acdlite committed Jun 14, 2015
1 parent f2b37cd commit cd9b192
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 8 deletions.
20 changes: 15 additions & 5 deletions src/createDispatcher.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,25 @@
/* @flow */

import compose from './utils/composeMiddleware';

export default function createDispatcher(store, middlewares = []) {
return function dispatcher(initialState, setState) {
let state = setState(store(initialState, {}));
import { Middleware, Store, Action, State, Dispatcher } from './types';

export default function createDispatcher(
store: Store,
middlewares: (Middleware[] | (getState: () => State) => Middleware[]) = []
): Dispatcher {
return function dispatcher(
initialState: State,
setState: (state: State) => State
) {
var state: State = setState(store(initialState, {}));

function dispatch(action) {
function dispatch(action: Action): Action {
state = setState(store(state, action));
return action;
}

function getState() {
function getState(): State {
return state;
}

Expand Down
10 changes: 7 additions & 3 deletions src/utils/composeStores.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
/* @flow */

import mapValues from 'lodash/object/mapValues';

export default function composeStores(stores) {
return function Composition(atom = {}, action) {
import { Store, Action, State } from '../types';

export default function composeStores(stores: Store[]): Store {
return function Composition(state: State = {}, action: Action) {
return mapValues(stores, (store, key) =>
store(atom[key], action)
store(state[key], action)
);
};
}

0 comments on commit cd9b192

Please sign in to comment.