Add types for package redux-batched-subscribe (#18394)

* Add redux-batched-subscribe types

* Address lint errors

* Add tests for redux-batched-subscribe

* Add sample batchFunction and corresponding types
This commit is contained in:
Dibyo Majumdar
2017-07-26 10:38:24 -07:00
committed by Andy
parent 1c793324df
commit bd48c6b64f
5 changed files with 70 additions and 0 deletions

View File

@@ -0,0 +1,11 @@
// Type definitions for redux-batched-subscribe 0.1
// Project: https://github.com/tappleby/redux-batched-subscribe
// Definitions by: Dibyo Majumdar <https://github.com/mDibyo>
// 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;

View File

@@ -0,0 +1,5 @@
{
"dependencies": {
"redux": ">=1.0.0"
}
}

View File

@@ -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<State> = () => ({});
const asyncNotify: BatchFunction = (() => {
let notifying: boolean = false;
return (notify: NotifyFunction) => {
if (notifying) {
return;
}
notifying = true;
setTimeout(() => {
notify();
notifying = false;
});
};
})();
const store: Store<State> = createStore(
rootReducer,
undefined,
batchedSubscribe(asyncNotify)
);

View File

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

View File

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