Added definition for rackt/redux

This commit is contained in:
wbuchwalter
2015-08-14 13:14:28 -04:00
parent e95958ac84
commit 5692d3499b
2 changed files with 83 additions and 0 deletions
+32
View File
@@ -0,0 +1,32 @@
/// <reference path="./redux.d.ts" />
function counter(state: any, action: any) {
if (!state) {
state = 0;
}
switch (action.type) {
case 'INCREMENT':
return state + 1;
case 'DECREMENT':
return state - 1;
default:
return state;
}
}
function loggingMiddleware() {
return (next: Redux.Dispatch) => (action: any) => {
console.log(action.type);
next(action);
};
}
let createStoreWithMiddleware = Redux.applyMiddleware(loggingMiddleware)(Redux.createStore);
let store = createStoreWithMiddleware(counter);
store.subscribe(() =>
console.log(store.getState())
);
store.dispatch({ type: 'INCREMENT' });
+51
View File
@@ -0,0 +1,51 @@
// Type definitions for Redux v1.0.0
// Project: https://github.com/rackt/redux
// Definitions by: William Buchwalter <https://github.com/wbuchwalter/>, Vincent Prouillet <https://github.com/Keats/>
// Definitions: https://github.com/borisyankov/DefinitelyTyped
declare module Redux {
interface ActionCreator extends Function {
(...args: any[]): any;
}
interface Reducer extends Function {
(state: any, action: any): any;
}
interface Dispatch extends Function {
(action: any): any;
}
interface StoreMethods {
dispatch: Dispatch;
getState(): any;
}
interface MiddlewareArg {
dispatch: Dispatch;
getState: Function;
}
interface Middleware extends Function {
(obj: MiddlewareArg): Function;
}
class Store {
getReducer(): Reducer;
replaceReducer(nextReducer: Reducer): void;
dispatch(action: any): any;
getState(): any;
subscribe(listener: Function): Function;
}
function createStore(reducer: Reducer, initialState?: any): Store;
function bindActionCreators<T>(actionCreators: T, dispatch: Dispatch): T;
function combineReducers(reducers: any): Reducer;
function applyMiddleware(...middleware: Middleware[]): Function;
}
declare module "redux" {
export = Redux;
}