Skip to content

Commit 5692d34

Browse files
committed
Added definition for rackt/redux
1 parent e95958a commit 5692d34

File tree

2 files changed

+83
-0
lines changed

2 files changed

+83
-0
lines changed

redux/redux-tests.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/// <reference path="./redux.d.ts" />
2+
3+
function counter(state: any, action: any) {
4+
if (!state) {
5+
state = 0;
6+
}
7+
switch (action.type) {
8+
case 'INCREMENT':
9+
return state + 1;
10+
case 'DECREMENT':
11+
return state - 1;
12+
default:
13+
return state;
14+
}
15+
}
16+
17+
function loggingMiddleware() {
18+
return (next: Redux.Dispatch) => (action: any) => {
19+
console.log(action.type);
20+
next(action);
21+
};
22+
}
23+
24+
let createStoreWithMiddleware = Redux.applyMiddleware(loggingMiddleware)(Redux.createStore);
25+
let store = createStoreWithMiddleware(counter);
26+
27+
28+
store.subscribe(() =>
29+
console.log(store.getState())
30+
);
31+
32+
store.dispatch({ type: 'INCREMENT' });

redux/redux.d.ts

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
// Type definitions for Redux v1.0.0
2+
// Project: https://github.com/rackt/redux
3+
// Definitions by: William Buchwalter <https://github.com/wbuchwalter/>, Vincent Prouillet <https://github.com/Keats/>
4+
// Definitions: https://github.com/borisyankov/DefinitelyTyped
5+
6+
declare module Redux {
7+
8+
interface ActionCreator extends Function {
9+
(...args: any[]): any;
10+
}
11+
12+
interface Reducer extends Function {
13+
(state: any, action: any): any;
14+
}
15+
16+
interface Dispatch extends Function {
17+
(action: any): any;
18+
}
19+
20+
interface StoreMethods {
21+
dispatch: Dispatch;
22+
getState(): any;
23+
}
24+
25+
26+
interface MiddlewareArg {
27+
dispatch: Dispatch;
28+
getState: Function;
29+
}
30+
31+
interface Middleware extends Function {
32+
(obj: MiddlewareArg): Function;
33+
}
34+
35+
class Store {
36+
getReducer(): Reducer;
37+
replaceReducer(nextReducer: Reducer): void;
38+
dispatch(action: any): any;
39+
getState(): any;
40+
subscribe(listener: Function): Function;
41+
}
42+
43+
function createStore(reducer: Reducer, initialState?: any): Store;
44+
function bindActionCreators<T>(actionCreators: T, dispatch: Dispatch): T;
45+
function combineReducers(reducers: any): Reducer;
46+
function applyMiddleware(...middleware: Middleware[]): Function;
47+
}
48+
49+
declare module "redux" {
50+
export = Redux;
51+
}

0 commit comments

Comments
 (0)