diff --git a/types/redux-cablecar/index.d.ts b/types/redux-cablecar/index.d.ts new file mode 100644 index 0000000000..f77177322e --- /dev/null +++ b/types/redux-cablecar/index.d.ts @@ -0,0 +1,30 @@ +// Type definitions for redux-cablecar 3.0 +// Project: https://github.com/ndhays/redux-cablecar#readme +// Definitions by: Christoph Flick +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 3.0 + +import { Action, Middleware, Store } from 'redux'; + +export interface Options { + connected?: () => void; + disconnected?: () => void; + params?: object; + prefix?: string; + optimisticOnFail?: boolean; +} + +export interface CableCar { + changeChannel: (channel: string, options?: Options) => void; + getChannel: () => string; + getParams: () => object; + perform: (method: string, payload?: any) => void; + send: (action: string) => void; +} + +declare var middleware: Middleware & { + connect: (store: Store, channel: string, options?: Options) => CableCar; + setProvider: (actionCableProvider: string) => void; +}; + +export default middleware; diff --git a/types/redux-cablecar/package.json b/types/redux-cablecar/package.json new file mode 100644 index 0000000000..3513bc4cf0 --- /dev/null +++ b/types/redux-cablecar/package.json @@ -0,0 +1,6 @@ +{ + "private": true, + "dependencies": { + "redux": "^4.0.4" + } +} diff --git a/types/redux-cablecar/redux-cablecar-tests.ts b/types/redux-cablecar/redux-cablecar-tests.ts new file mode 100644 index 0000000000..dab2717dc9 --- /dev/null +++ b/types/redux-cablecar/redux-cablecar-tests.ts @@ -0,0 +1,18 @@ +import cablecar, { Options } from 'redux-cablecar'; +import { applyMiddleware, createStore } from 'redux'; + +const store = createStore(() => null, applyMiddleware(cablecar)); + +cablecar.setProvider('testProvider'); + +const car = cablecar.connect(store, 'testChannel'); + +const options: Options = { + connected: () => { }, + prefix: 'ASDF' +}; + +const anotherCar = cablecar.connect(store, 'secondeTestChannel', options); + +car.perform('activate', { data: 'something' }); +anotherCar.send('noice_action'); diff --git a/types/redux-cablecar/tsconfig.json b/types/redux-cablecar/tsconfig.json new file mode 100644 index 0000000000..e7f26eb916 --- /dev/null +++ b/types/redux-cablecar/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-cablecar-tests.ts" + ] +} diff --git a/types/redux-cablecar/tslint.json b/types/redux-cablecar/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/redux-cablecar/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }