Skip to content

Commit 305f142

Browse files
committed
Merge pull request #299 from gaearon/remove-flow
Remove Flow types for now
2 parents b51338f + 9321dea commit 305f142

10 files changed

+17
-99
lines changed

src/createStore.js

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,3 @@
1-
/* @flow */
2-
/*eslint-disable */
3-
import type { State, Reducer, Action, IntermediateAction, Store } from './index';
4-
/*eslint-enable */
5-
61
import invariant from 'invariant';
72
import isPlainObject from './utils/isPlainObject';
83

@@ -13,10 +8,7 @@ export var ActionTypes = {
138
INIT: '@@redux/INIT'
149
};
1510

16-
export default function createStore(
17-
reducer: Reducer,
18-
initialState: State
19-
): Store {
11+
export default function createStore(reducer, initialState) {
2012
invariant(
2113
typeof reducer === 'function',
2214
'Expected the reducer to be a function.'
@@ -30,7 +22,7 @@ export default function createStore(
3022
return currentState;
3123
}
3224

33-
function subscribe(listener: Function) {
25+
function subscribe(listener) {
3426
listeners.push(listener);
3527

3628
return function unsubscribe() {
@@ -39,7 +31,7 @@ export default function createStore(
3931
};
4032
}
4133

42-
function dispatch(action: Action) {
34+
function dispatch(action) {
4335
invariant(
4436
isPlainObject(action),
4537
'Actions must be plain objects. Use custom middleware for async actions.'
@@ -54,7 +46,7 @@ export default function createStore(
5446
return currentReducer;
5547
}
5648

57-
function replaceReducer(nextReducer: Reducer) {
49+
function replaceReducer(nextReducer) {
5850
currentReducer = nextReducer;
5951
dispatch({ type: ActionTypes.INIT });
6052
}

src/index.js

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,3 @@
1-
/* @flow */
2-
3-
export type State = any;
4-
export type Action = Object;
5-
export type IntermediateAction = any;
6-
export type Dispatch = (a: Action | IntermediateAction) => any;
7-
export type Reducer<S, A> = (state: S, action: A) => S;
8-
export type ActionCreator = (...args: any) => Action | IntermediateAction;
9-
10-
export type MiddlewareArgs = {
11-
dispatch: Dispatch;
12-
getState: () => State;
13-
};
14-
15-
export type Middleware = (args: MiddlewareArgs) =>
16-
(next: Dispatch) =>
17-
Dispatch;
18-
19-
export type Store = {
20-
dispatch: Dispatch;
21-
getState: () => State;
22-
getReducer: () => Reducer;
23-
replaceReducer: (nextReducer: Reducer) => void;
24-
subscribe: (listener: () => void) => () => void;
25-
};
26-
27-
export type CreateStore = (
28-
reducer: Reducer,
29-
initialState: State
30-
) => Store;
31-
32-
export type HigherOrderStore = (
33-
next: CreateStore
34-
) => CreateStore;
35-
361
import createStore from './createStore';
372
import compose from './utils/compose';
383
import combineReducers from './utils/combineReducers';

src/utils/applyMiddleware.js

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,3 @@
1-
/* @flow */
2-
/*eslint-disable */
3-
import type {
4-
Dispatch, Middleware, Reducer, State,
5-
Store, CreateStore, HigherOrderStore
6-
} from '../index';
7-
/*eslint-enable */
8-
91
import compose from './compose';
102
import composeMiddleware from './composeMiddleware';
113

@@ -16,10 +8,8 @@ import composeMiddleware from './composeMiddleware';
168
* @param {...Function} ...middlewares
179
* @return {Function} A higher-order store
1810
*/
19-
export default function applyMiddleware(
20-
...middlewares: Array<Middleware>
21-
): HigherOrderStore {
22-
return (next: CreateStore) => (reducer: Reducer, initialState: State) => {
11+
export default function applyMiddleware(...middlewares) {
12+
return (next) => (reducer, initialState) => {
2313
var store = next(reducer, initialState);
2414
var middleware = composeMiddleware(...middlewares);
2515
var composedDispatch = () => {};

src/utils/bindActionCreators.js

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,6 @@
1-
/* @flow */
2-
/*eslint-disable */
3-
import type { Dispatch } from '../index';
4-
/*eslint-enable */
5-
61
import mapValues from '../utils/mapValues';
72

8-
export default function bindActionCreators(
9-
actionCreators: Object,
10-
dispatch: Dispatch
11-
): Object {
3+
export default function bindActionCreators(actionCreators, dispatch) {
124
return mapValues(actionCreators, actionCreator =>
135
(...args) => dispatch(actionCreator(...args))
146
);

src/utils/combineReducers.js

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,9 @@
1-
/* @flow */
2-
/*eslint-disable */
3-
import type { Action, State, Reducer } from '../index';
4-
/*eslint-enable */
5-
61
import mapValues from '../utils/mapValues';
72
import pick from '../utils/pick';
83
import invariant from 'invariant';
94
import { ActionTypes } from '../createStore';
105

11-
function getErrorMessage(key: String, action: Action): string {
6+
function getErrorMessage(key, action) {
127
var actionType = action && action.type;
138
var actionName = actionType && `"${actionType}"` || 'an action';
149

@@ -18,7 +13,7 @@ function getErrorMessage(key: String, action: Action): string {
1813
);
1914
}
2015

21-
export default function combineReducers(reducers: Object): Reducer {
16+
export default function combineReducers(reducers) {
2217
var finalReducers = pick(reducers, (val) => typeof val === 'function');
2318

2419
Object.keys(finalReducers).forEach(key => {
@@ -43,7 +38,7 @@ export default function combineReducers(reducers: Object): Reducer {
4338
);
4439
});
4540

46-
return function composition(state: State = {}, action: Action): State {
41+
return function composition(state = {}, action) {
4742
return mapValues(finalReducers, (reducer, key) => {
4843
var newState = reducer(state[key], action);
4944
invariant(

src/utils/compose.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1-
/* @flow */
2-
31
/**
42
* Composes functions from left to right
53
* @param {...Function} funcs - Functions to compose
64
* @return {Function}
75
*/
8-
export default function compose(...funcs: Array<Function>): Function {
6+
export default function compose(...funcs) {
97
return funcs.reduceRight((composed, f) => f(composed));
108
}

src/utils/composeMiddleware.js

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,13 @@
1-
/* @flow */
2-
/*eslint-disable */
3-
import type { Dispatch, Middleware, MiddlewareArgs } from '../index';
4-
/*eslint-enable */
5-
61
import compose from './compose';
72

83
/**
94
* Compose middleware from left to right
105
* @param {...Function} middlewares
116
* @return {Function}
127
*/
13-
export default function composeMiddleware(
14-
...middlewares: Array<Middleware>
15-
): Middleware {
16-
return (args: MiddlewareArgs) => (next: Dispatch) => {
8+
export default function composeMiddleware(...middlewares) {
9+
return args => rawDispatch => {
1710
var dispatchChain = middlewares.map(middleware => middleware(args));
18-
dispatchChain.push(next);
19-
return compose.apply(null, dispatchChain);
11+
return compose(...dispatchChain, rawDispatch);
2012
};
2113
}

src/utils/isPlainObject.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
/* @flow */
2-
3-
export default function isPlainObject(obj: Object): boolean {
1+
export default function isPlainObject(obj) {
42
if (!obj) {
53
return false;
64
}

src/utils/mapValues.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
/* @flow */
2-
3-
export default function mapValues(obj: Object, fn: Function): Object {
1+
export default function mapValues(obj, fn) {
42
return Object.keys(obj).reduce((result, key) => {
53
result[key] = fn(obj[key], key);
64
return result;

src/utils/pick.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
/* @flow */
2-
3-
export default function pick(obj: Object, fn: Function): Object {
1+
export default function pick(obj, fn) {
42
return Object.keys(obj).reduce((result, key) => {
53
if (fn(obj[key])) {
64
result[key] = obj[key];

0 commit comments

Comments
 (0)