Merge pull request #22465 from unindented/redux-injectable-store

Add types for redux-injectable-store 1.0
This commit is contained in:
Paul van Brenk
2017-12-28 16:04:49 -08:00
committed by GitHub
5 changed files with 82 additions and 0 deletions
+28
View File
@@ -0,0 +1,28 @@
// Type definitions for redux-injectable-store 1.0
// Project: https://github.com/lelandrichardson/redux-injectable-store#readme
// Definitions by: Daniel Perez Alvarez <https://github.com/unindented>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
import { Reducer, Store, StoreEnhancer } from "redux";
export interface InjectableStore<S> extends Store<S> {
inject(namespace: string, reducer: Reducer<any>): void;
injectAll(reducers: { [key: string]: Reducer<any> }): void;
clearReducers(): void;
}
export type WrapReducer<S> = (reducer: Reducer<S>) => Reducer<S>;
export interface InjectableStoreCreator {
<S>(
enhancer?: StoreEnhancer<S>,
wrapReducer?: WrapReducer<S>
): InjectableStore<S>;
<S>(
preloadedState: S,
enhancer?: StoreEnhancer<S>,
wrapReducer?: WrapReducer<S>
): InjectableStore<S>;
}
export const createInjectableStore: InjectableStoreCreator;
@@ -0,0 +1,6 @@
{
"private": true,
"dependencies": {
"redux": "^3.6.0"
}
}
@@ -0,0 +1,24 @@
import { createInjectableStore } from "redux-injectable-store";
import { applyMiddleware, compose, AnyAction, Middleware } from "redux";
interface State {
foo: string;
bar?: string;
baz?: string;
}
const initialState: State = { foo: "bar" };
const middleware: Middleware[] = [];
const enhancer = applyMiddleware(...middleware);
const store = createInjectableStore<State>(initialState, enhancer);
const anotherStore = createInjectableStore<State>(initialState, enhancer, reducer => reducer);
const dummyReducer = (state: string) => state;
store.inject("foo", dummyReducer);
anotherStore.injectAll({
bar: dummyReducer,
baz: dummyReducer
});
@@ -0,0 +1,23 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": [
"es6"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"baseUrl": "../",
"typeRoots": [
"../"
],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"index.d.ts",
"redux-injectable-store-tests.ts"
]
}
+1
View File
@@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }