diff --git a/types/redux-socket.io/index.d.ts b/types/redux-socket.io/index.d.ts new file mode 100644 index 0000000000..dfd608868b --- /dev/null +++ b/types/redux-socket.io/index.d.ts @@ -0,0 +1,19 @@ +// Type definitions for redux-socket.io 1.4 +// Project: https://github.com/itaylor/redux-socket.io#readme +// Definitions by: Igor Voropaev +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +/// + +import { Middleware, Action, Dispatch } from 'redux'; + +export interface MiddlewareOptions { + eventName?: string; + execute?: (action: Action, emitBound: SocketIOClient.Socket, next: Dispatch, dispatch: Dispatch) => any; +} + +export default function createSocketIoMiddleware( + socket: SocketIOClient.Socket, + criteria: (string | ReadonlyArray | ((type: string, action: Action) => boolean)), + options?: MiddlewareOptions +): Middleware; diff --git a/types/redux-socket.io/package.json b/types/redux-socket.io/package.json new file mode 100644 index 0000000000..6d68bf2f9b --- /dev/null +++ b/types/redux-socket.io/package.json @@ -0,0 +1,6 @@ +{ + "private": true, + "dependencies": { + "redux": "^3.6.0" + } +} diff --git a/types/redux-socket.io/redux-socket.io-tests.ts b/types/redux-socket.io/redux-socket.io-tests.ts new file mode 100644 index 0000000000..f67a86393a --- /dev/null +++ b/types/redux-socket.io/redux-socket.io-tests.ts @@ -0,0 +1,10 @@ +import * as ioclient from 'socket.io-client'; +import createSocketIoMiddleware from 'redux-socket.io'; +import { Action } from 'redux'; + +const socketio = ioclient("test"); + +const SocketIOMiddleware1 = createSocketIoMiddleware(socketio, "test"); +const SocketIOMiddleware2 = createSocketIoMiddleware(socketio, ["test1", "test2"]); +const SocketIOMiddleware3 = createSocketIoMiddleware(socketio, (type: string, action: Action) => (type === 'test')); +const SocketIOMiddleware4 = createSocketIoMiddleware(socketio, "", { eventName: "test" }); diff --git a/types/redux-socket.io/tsconfig.json b/types/redux-socket.io/tsconfig.json new file mode 100644 index 0000000000..8636bd654d --- /dev/null +++ b/types/redux-socket.io/tsconfig.json @@ -0,0 +1,23 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictFunctionTypes": true, + "strictNullChecks": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "redux-socket.io-tests.ts" + ] +} diff --git a/types/redux-socket.io/tslint.json b/types/redux-socket.io/tslint.json new file mode 100644 index 0000000000..6746359dda --- /dev/null +++ b/types/redux-socket.io/tslint.json @@ -0,0 +1,3 @@ +{ + "extends": "dtslint/dt.json" +}