mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-04-18 12:08:59 +08:00
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:
11
types/redux-batched-subscribe/index.d.ts
vendored
Normal file
11
types/redux-batched-subscribe/index.d.ts
vendored
Normal 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;
|
||||
5
types/redux-batched-subscribe/package.json
Normal file
5
types/redux-batched-subscribe/package.json
Normal file
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"dependencies": {
|
||||
"redux": ">=1.0.0"
|
||||
}
|
||||
}
|
||||
@@ -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)
|
||||
);
|
||||
23
types/redux-batched-subscribe/tsconfig.json
Normal file
23
types/redux-batched-subscribe/tsconfig.json
Normal 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"
|
||||
]
|
||||
}
|
||||
1
types/redux-batched-subscribe/tslint.json
Normal file
1
types/redux-batched-subscribe/tslint.json
Normal file
@@ -0,0 +1 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
Reference in New Issue
Block a user