From caf4f56b106ffc3068f9aca3cb193137170e0241 Mon Sep 17 00:00:00 2001 From: Nikita Umnov Date: Thu, 15 Aug 2019 17:20:38 +0700 Subject: [PATCH] add types definition (#218) * add types definition --- index.d.ts | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++++ package.json | 2 ++ 2 files changed, 61 insertions(+) create mode 100644 index.d.ts diff --git a/index.d.ts b/index.d.ts new file mode 100644 index 0000000..8546d8f --- /dev/null +++ b/index.d.ts @@ -0,0 +1,59 @@ +import SocketIOClient from "socket.io-client"; +import { + DefaultComputed, + DefaultData, + DefaultMethods, + DefaultProps, + PropsDefinition, +} from "vue/types/options"; +import { Vue } from "vue/types/vue"; +import { PluginFunction, PluginObject } from "vue"; +import { Store } from "vuex"; + +interface socketHandler { + (this: T, ...args: any[]): void +} + +interface Sockets { + [key: string]: socketHandler +} + +declare module 'vue/types/vue' { + interface Vue { + $socket: SocketIOClient.Socket, + sockets: { + subscribe(eventName: string, handler: socketHandler): void, + unsubscribe(eventName: string): void, + } + } +} + +declare module 'vue/types/options' { + interface ComponentOptions< + V extends Vue, + Data=DefaultData, + Methods=DefaultMethods, + Computed=DefaultComputed, + PropsDef=PropsDefinition, + Props=DefaultProps> { + sockets?: Sockets + } +} + +export interface VueSocketOptions { + debug?: boolean; + connection: string | SocketIOClient.Socket, + vuex?: { + store?: Store, + actionPrefix?: string, + mutationPrefix?: string, + options?: { + useConnectionNamespace?: boolean + } + } +} + +export default class VueSocketIO implements PluginObject { + constructor (options: VueSocketOptions); + install: PluginFunction +} diff --git a/package.json b/package.json index f486ca9..c0d0749 100644 --- a/package.json +++ b/package.json @@ -38,6 +38,8 @@ "@babel/preset-env": "^7.1.0", "babel-loader": "^8.0.4", "cross-env": "^5.2.0", + "vue": "^2.6.10", + "vuex": "^3.1.1", "webpack": "^4.23.1", "webpack-cli": "^3.1.2" }