diff --git a/types/redux-batched-subscribe/index.d.ts b/types/redux-batched-subscribe/index.d.ts new file mode 100644 index 0000000000..e3f5345591 --- /dev/null +++ b/types/redux-batched-subscribe/index.d.ts @@ -0,0 +1,11 @@ +// Type definitions for redux-batched-subscribe 0.1 +// Project: https://github.com/tappleby/redux-batched-subscribe +// Definitions by: Dibyo Majumdar +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +import { GenericStoreEnhancer } from 'redux'; + +export type NotifyFunction = () => void; +export type BatchFunction = (notify: NotifyFunction) => void; + +export function batchedSubscribe(batch: BatchFunction): GenericStoreEnhancer; diff --git a/types/redux-batched-subscribe/package.json b/types/redux-batched-subscribe/package.json new file mode 100644 index 0000000000..c4ea3b7de6 --- /dev/null +++ b/types/redux-batched-subscribe/package.json @@ -0,0 +1,5 @@ +{ + "dependencies": { + "redux": ">=1.0.0" + } +} diff --git a/types/redux-batched-subscribe/redux-batched-subscribe-tests.ts b/types/redux-batched-subscribe/redux-batched-subscribe-tests.ts new file mode 100644 index 0000000000..5bfa3e0aa6 --- /dev/null +++ b/types/redux-batched-subscribe/redux-batched-subscribe-tests.ts @@ -0,0 +1,30 @@ +import { createStore, Store, Reducer } from "redux"; +import { batchedSubscribe, BatchFunction, NotifyFunction } from 'redux-batched-subscribe'; + +interface State { + [key: string]: any; +} + +const rootReducer: Reducer = () => ({}); + +const asyncNotify: BatchFunction = (() => { + let notifying: boolean = false; + + return (notify: NotifyFunction) => { + if (notifying) { + return; + } + + notifying = true; + setTimeout(() => { + notify(); + notifying = false; + }); + }; +})(); + +const store: Store = createStore( + rootReducer, + undefined, + batchedSubscribe(asyncNotify) +); diff --git a/types/redux-batched-subscribe/tsconfig.json b/types/redux-batched-subscribe/tsconfig.json new file mode 100644 index 0000000000..80aea65c77 --- /dev/null +++ b/types/redux-batched-subscribe/tsconfig.json @@ -0,0 +1,23 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6", + "dom" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "redux-batched-subscribe-tests.ts" + ] +} diff --git a/types/redux-batched-subscribe/tslint.json b/types/redux-batched-subscribe/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/redux-batched-subscribe/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }