Skip to content

Remove Flow types for now #299

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 22, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 4 additions & 12 deletions src/createStore.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
/* @flow */
/*eslint-disable */
import type { State, Reducer, Action, IntermediateAction, Store } from './index';
/*eslint-enable */

import invariant from 'invariant';
import isPlainObject from './utils/isPlainObject';

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

export default function createStore(
reducer: Reducer,
initialState: State
): Store {
export default function createStore(reducer, initialState) {
invariant(
typeof reducer === 'function',
'Expected the reducer to be a function.'
Expand All @@ -30,7 +22,7 @@ export default function createStore(
return currentState;
}

function subscribe(listener: Function) {
function subscribe(listener) {
listeners.push(listener);

return function unsubscribe() {
Expand All @@ -39,7 +31,7 @@ export default function createStore(
};
}

function dispatch(action: Action) {
function dispatch(action) {
invariant(
isPlainObject(action),
'Actions must be plain objects. Use custom middleware for async actions.'
Expand All @@ -54,7 +46,7 @@ export default function createStore(
return currentReducer;
}

function replaceReducer(nextReducer: Reducer) {
function replaceReducer(nextReducer) {
currentReducer = nextReducer;
dispatch({ type: ActionTypes.INIT });
}
Expand Down
35 changes: 0 additions & 35 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,38 +1,3 @@
/* @flow */

export type State = any;
export type Action = Object;
export type IntermediateAction = any;
export type Dispatch = (a: Action | IntermediateAction) => any;
export type Reducer<S, A> = (state: S, action: A) => S;
export type ActionCreator = (...args: any) => Action | IntermediateAction;

export type MiddlewareArgs = {
dispatch: Dispatch;
getState: () => State;
};

export type Middleware = (args: MiddlewareArgs) =>
(next: Dispatch) =>
Dispatch;

export type Store = {
dispatch: Dispatch;
getState: () => State;
getReducer: () => Reducer;
replaceReducer: (nextReducer: Reducer) => void;
subscribe: (listener: () => void) => () => void;
};

export type CreateStore = (
reducer: Reducer,
initialState: State
) => Store;

export type HigherOrderStore = (
next: CreateStore
) => CreateStore;

import createStore from './createStore';
import compose from './utils/compose';
import combineReducers from './utils/combineReducers';
Expand Down
14 changes: 2 additions & 12 deletions src/utils/applyMiddleware.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,3 @@
/* @flow */
/*eslint-disable */
import type {
Dispatch, Middleware, Reducer, State,
Store, CreateStore, HigherOrderStore
} from '../index';
/*eslint-enable */

import compose from './compose';
import composeMiddleware from './composeMiddleware';

Expand All @@ -16,10 +8,8 @@ import composeMiddleware from './composeMiddleware';
* @param {...Function} ...middlewares
* @return {Function} A higher-order store
*/
export default function applyMiddleware(
...middlewares: Array<Middleware>
): HigherOrderStore {
return (next: CreateStore) => (reducer: Reducer, initialState: State) => {
export default function applyMiddleware(...middlewares) {
return (next) => (reducer, initialState) => {
var store = next(reducer, initialState);
var middleware = composeMiddleware(...middlewares);
var composedDispatch = () => {};
Expand Down
10 changes: 1 addition & 9 deletions src/utils/bindActionCreators.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,6 @@
/* @flow */
/*eslint-disable */
import type { Dispatch } from '../index';
/*eslint-enable */

import mapValues from '../utils/mapValues';

export default function bindActionCreators(
actionCreators: Object,
dispatch: Dispatch
): Object {
export default function bindActionCreators(actionCreators, dispatch) {
return mapValues(actionCreators, actionCreator =>
(...args) => dispatch(actionCreator(...args))
);
Expand Down
11 changes: 3 additions & 8 deletions src/utils/combineReducers.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
/* @flow */
/*eslint-disable */
import type { Action, State, Reducer } from '../index';
/*eslint-enable */

import mapValues from '../utils/mapValues';
import pick from '../utils/pick';
import invariant from 'invariant';
import { ActionTypes } from '../createStore';

function getErrorMessage(key: String, action: Action): string {
function getErrorMessage(key, action) {
var actionType = action && action.type;
var actionName = actionType && `"${actionType}"` || 'an action';

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

export default function combineReducers(reducers: Object): Reducer {
export default function combineReducers(reducers) {
var finalReducers = pick(reducers, (val) => typeof val === 'function');

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

return function composition(state: State = {}, action: Action): State {
return function composition(state = {}, action) {
return mapValues(finalReducers, (reducer, key) => {
var newState = reducer(state[key], action);
invariant(
Expand Down
4 changes: 1 addition & 3 deletions src/utils/compose.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
/* @flow */

/**
* Composes functions from left to right
* @param {...Function} funcs - Functions to compose
* @return {Function}
*/
export default function compose(...funcs: Array<Function>): Function {
export default function compose(...funcs) {
return funcs.reduceRight((composed, f) => f(composed));
}
14 changes: 3 additions & 11 deletions src/utils/composeMiddleware.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,13 @@
/* @flow */
/*eslint-disable */
import type { Dispatch, Middleware, MiddlewareArgs } from '../index';
/*eslint-enable */

import compose from './compose';

/**
* Compose middleware from left to right
* @param {...Function} middlewares
* @return {Function}
*/
export default function composeMiddleware(
...middlewares: Array<Middleware>
): Middleware {
return (args: MiddlewareArgs) => (next: Dispatch) => {
export default function composeMiddleware(...middlewares) {
return args => rawDispatch => {
var dispatchChain = middlewares.map(middleware => middleware(args));
dispatchChain.push(next);
return compose.apply(null, dispatchChain);
return compose(...dispatchChain, rawDispatch);
};
}
4 changes: 1 addition & 3 deletions src/utils/isPlainObject.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
/* @flow */

export default function isPlainObject(obj: Object): boolean {
export default function isPlainObject(obj) {
if (!obj) {
return false;
}
Expand Down
4 changes: 1 addition & 3 deletions src/utils/mapValues.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
/* @flow */

export default function mapValues(obj: Object, fn: Function): Object {
export default function mapValues(obj, fn) {
return Object.keys(obj).reduce((result, key) => {
result[key] = fn(obj[key], key);
return result;
Expand Down
4 changes: 1 addition & 3 deletions src/utils/pick.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
/* @flow */

export default function pick(obj: Object, fn: Function): Object {
export default function pick(obj, fn) {
return Object.keys(obj).reduce((result, key) => {
if (fn(obj[key])) {
result[key] = obj[key];
Expand Down