From 5692d3499b2d2d4d7e5311d6251ad13cd140ffba Mon Sep 17 00:00:00 2001 From: wbuchwalter Date: Fri, 14 Aug 2015 13:14:28 -0400 Subject: [PATCH] Added definition for rackt/redux --- redux/redux-tests.ts | 32 +++++++++++++++++++++++++++ redux/redux.d.ts | 51 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 83 insertions(+) create mode 100644 redux/redux-tests.ts create mode 100644 redux/redux.d.ts diff --git a/redux/redux-tests.ts b/redux/redux-tests.ts new file mode 100644 index 000000000..cc0c93499 --- /dev/null +++ b/redux/redux-tests.ts @@ -0,0 +1,32 @@ +/// + +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' }); diff --git a/redux/redux.d.ts b/redux/redux.d.ts new file mode 100644 index 000000000..1f33d1559 --- /dev/null +++ b/redux/redux.d.ts @@ -0,0 +1,51 @@ +// Type definitions for Redux v1.0.0 +// Project: https://github.com/rackt/redux +// Definitions by: William Buchwalter , Vincent Prouillet +// 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(actionCreators: T, dispatch: Dispatch): T; + function combineReducers(reducers: any): Reducer; + function applyMiddleware(...middleware: Middleware[]): Function; +} + +declare module "redux" { + export = Redux; +} \ No newline at end of file