Added redux-socket.io type (#22773)

* Added redux-socket.io type

* Fixed bad dependency on socket.io
This commit is contained in:
Igor Snake
2018-01-10 23:29:28 +05:00
committed by Ryan Cavanaugh
parent 2b8c88b0b6
commit 68e71f0c21
5 changed files with 61 additions and 0 deletions

19
types/redux-socket.io/index.d.ts vendored Normal file
View File

@@ -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 <https://github.com/snakeego>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
/// <reference types="socket.io-client" />
import { Middleware, Action, Dispatch } from 'redux';
export interface MiddlewareOptions {
eventName?: string;
execute?: <S>(action: Action, emitBound: SocketIOClient.Socket, next: Dispatch<S>, dispatch: Dispatch<S>) => any;
}
export default function createSocketIoMiddleware(
socket: SocketIOClient.Socket,
criteria: (string | ReadonlyArray<string> | ((type: string, action: Action) => boolean)),
options?: MiddlewareOptions
): Middleware;

View File

@@ -0,0 +1,6 @@
{
"private": true,
"dependencies": {
"redux": "^3.6.0"
}
}

View File

@@ -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" });

View File

@@ -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"
]
}

View File

@@ -0,0 +1,3 @@
{
"extends": "dtslint/dt.json"
}