-
-
Notifications
You must be signed in to change notification settings - Fork 15.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #254 from gaearon/flow-types-take-3
Flow types, take 3 (actually 4)
- Loading branch information
Showing
14 changed files
with
151 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
[ignore] | ||
.*/lib | ||
.*/test | ||
|
||
[include] | ||
|
||
[libs] | ||
|
||
[options] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* @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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,10 @@ | ||
/* @flow */ | ||
|
||
/** | ||
* Composes functions from left to right | ||
* @param {...Function} funcs - Functions to compose | ||
* @return {Function} | ||
*/ | ||
export default function compose(...funcs) { | ||
export default function compose(...funcs: Array<Function>): Function { | ||
return funcs.reduceRight((composed, f) => f(composed)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,21 @@ | ||
/* @flow */ | ||
/*eslint-disable */ | ||
import type { Dispatch, Middleware, MiddlewareArgs } from '../types'; | ||
/*eslint-enable */ | ||
|
||
import compose from './compose'; | ||
|
||
/** | ||
* Compose middleware from left to right | ||
* @param {...Function} middlewares | ||
* @return {Function} | ||
*/ | ||
export default function composeMiddleware(...middlewares) { | ||
return methods => next => compose(...middlewares.map(m => m(methods)), next); | ||
export default function composeMiddleware( | ||
...middlewares: Array<Middleware> | ||
): Middleware { | ||
return (args: MiddlewareArgs) => (next: Dispatch) => { | ||
var dispatchChain = middlewares.map(middleware => middleware(args)); | ||
dispatchChain.push(next); | ||
return compose.apply(null, dispatchChain); | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,10 @@ | ||
export default function isPlainObject(obj) { | ||
return obj ? typeof obj === 'object' && Object.getPrototypeOf(obj) === Object.prototype : false; | ||
/* @flow */ | ||
|
||
export default function isPlainObject(obj: Object): boolean { | ||
if (!obj) { | ||
return false; | ||
} | ||
|
||
return typeof obj === 'object' && | ||
Object.getPrototypeOf(obj) === Object.prototype; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters