forked from flow-typed/flow-typed
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add library definition for socket.io-client (flow-typed#1523)
- Loading branch information
1 parent
021abc9
commit dfb2df4
Showing
2 changed files
with
112 additions
and
0 deletions.
There are no files selected for viewing
62 changes: 62 additions & 0 deletions
62
definitions/npm/socket.io-client_v2.x.x/flow_v0.34.x-/socket.io-client_v2.x.x.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
declare module "socket.io-client" { | ||
declare type Callback = (...args: mixed[]) => void; | ||
|
||
declare type ManagerOptions = $Shape<{ | ||
path: string, | ||
reconnection: boolean, | ||
reconnectionAttempts: number, | ||
reconnectionDelay: number, | ||
reconnectionDelayMax: number, | ||
randomizationFactor: number, | ||
timeout: number, | ||
parser: any | ||
}>; | ||
|
||
declare type LookupOptions = $Shape<{ forceNew: boolean }>; | ||
|
||
declare type SocketOptions = $Shape<{ query: string }>; | ||
|
||
declare class Emitter { | ||
on(event: string, cb: Callback): this; | ||
addEventListener(event: string, cb: Callback): this; | ||
once(event: string, cb: Callback): this; | ||
off(event: string, cb: Callback): this; | ||
removeListener(event: string, cb: Callback): this; | ||
removeAllListeners(event: string, cb: Callback): this; | ||
removeEventListener(event: string, cb: Callback): this; | ||
emit(event: string, payload: mixed): this; | ||
listeners(event: string): Callback[]; | ||
hasListeners(event: string): boolean; | ||
} | ||
|
||
declare export class Manager extends Emitter { | ||
static (uri?: string, opts?: ManagerOptions): this; | ||
reconnection(boolean): this; | ||
reconnectionAttempts(number): this; | ||
reconnectionDelay(number): this; | ||
randomizationFactor(number): this; | ||
reconnectionDelayMax(number): this; | ||
timeout(number): this; | ||
open(fn?: (err?: Error) => void, opts?: ManagerOptions): this; | ||
connect(fn: any, opts: any): this; | ||
socket(namespace: string, opts?: SocketOptions): Socket; | ||
} | ||
|
||
declare export class Socket extends Emitter { | ||
static (io: Manager, nsp: string, opts?: SocketOptions): this; | ||
open(): this; | ||
connect(): this; | ||
send(...args: mixed[]): this; | ||
emit(event: string, ...args: mixed[]): this; // overrides Emitter#emit | ||
close(): this; | ||
disconnect(): this; | ||
compress(boolean): this; | ||
io: Manager; | ||
} | ||
|
||
declare export var protocol: 4; | ||
|
||
declare type Lookup = (uri?: string, opts?: LookupOptions) => Socket; | ||
declare export var connect: Lookup; | ||
declare export default Lookup | ||
} |
50 changes: 50 additions & 0 deletions
50
definitions/npm/socket.io-client_v2.x.x/test_socket.io-client_v2.x.x.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import io from "socket.io-client"; | ||
|
||
io("foo"); | ||
io("foo", {}); | ||
io("foo", { forceNew: true }); | ||
|
||
const socket = io("foo") | ||
.open() | ||
.connect() | ||
.send({ foo: "bar" }, { bar: "baz" }) | ||
.emit("bar", { foo: "bar" }) // overrides Emitter#emit | ||
.close() | ||
.disconnect() | ||
.compress(true) | ||
.on("foo", () => {}) | ||
.addEventListener("foo", () => {}) | ||
.once("foo", () => {}) | ||
.off("foo", () => {}) | ||
.removeListener("foo", () => {}) | ||
.removeAllListeners("foo", () => {}) | ||
.removeEventListener("foo", () => {}); | ||
|
||
const callbacks = socket.listeners("foo"); | ||
const hasFooListener = socket.hasListeners("foo"); | ||
|
||
const manager = socket.io | ||
.reconnection(true) | ||
.reconnectionAttempts(5) | ||
.reconnectionDelay(5) | ||
.randomizationFactor(5) | ||
.reconnectionDelayMax(5) | ||
.timeout(5) | ||
.open(err => {}, {}) | ||
.connect(() => {}, {}) | ||
.on("foo", () => {}) | ||
.addEventListener("foo", () => {}) | ||
.once("foo", () => {}) | ||
.off("foo", () => {}) | ||
.removeListener("foo", () => {}) | ||
.removeAllListeners("foo", () => {}) | ||
.removeEventListener("foo", () => {}) | ||
.emit("foo", { bar: "baz" }); | ||
|
||
manager.socket("/baz", {}); | ||
|
||
// $ExpectError | ||
io("foo", { invalid_key: 5 }); | ||
|
||
// $ExpectError | ||
io(5); |