mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-07-04 09:10:09 +00:00
[pouch-redux-middleware] v1.2 (#38277)
* Updating pouch-redux-middleware for v1.2 * Fixing spacing
This commit is contained in:
committed by
Ben Lichtman
parent
2f7e7ab580
commit
56b659e0f0
46
types/pouch-redux-middleware/index.d.ts
vendored
46
types/pouch-redux-middleware/index.d.ts
vendored
@@ -1,4 +1,4 @@
|
||||
// Type definitions for pouch-redux-middleware 0.5
|
||||
// Type definitions for pouch-redux-middleware 1.2
|
||||
// Project: https://github.com/pgte/pouch-redux-middleware
|
||||
// Definitions by: Adam Charron <https://github.com/charrondev>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
@@ -7,27 +7,27 @@
|
||||
import { Dispatch, Action, Middleware } from 'redux';
|
||||
import * as PouchDB from 'pouchdb';
|
||||
|
||||
export interface Document {
|
||||
_id: any;
|
||||
[field: string]: any;
|
||||
export type Document<T = {[field: string]: any}> = PouchDB.Core.IdMeta & T;
|
||||
|
||||
export interface Path<T = {[field: string]: any}> {
|
||||
path: string;
|
||||
db: PouchDB.Database<T>;
|
||||
scheduleRemove?(doc: Document<T>): void;
|
||||
scheduleInset?(doc: Document<T>): void;
|
||||
propagateDelete?(doc: Document<T>, dispatch: Dispatch<any>): void;
|
||||
propagateBatchInsert?(doc: Array<Document<T>>, dispatch: Dispatch<any>): void;
|
||||
propagateInsert?(doc: Document<T>, dispatch: Dispatch<any>): void;
|
||||
propagateUpdate?(doc: Document<T>, dispatch: Dispatch<any>): void;
|
||||
handleResponse?(err: Error, data: any, errorCallback: (err: Error) => void): void;
|
||||
initialBatchDispatched?(err?: Error): void;
|
||||
queue?(...args: any[]): any;
|
||||
docs?: any;
|
||||
actions: {
|
||||
remove(doc: Document<T>): Action;
|
||||
update(doc: Document<T>): Action;
|
||||
insert(doc: Document<T>): Action;
|
||||
batchInsert(docs: Array<Document<T>>): Action;
|
||||
};
|
||||
}
|
||||
|
||||
export interface Path {
|
||||
path: string;
|
||||
db: PouchDB.Database<any>;
|
||||
scheduleRemove?(doc: Document): void;
|
||||
scheduleInset?(doc: Document): void;
|
||||
propagateDelete?(doc: Document, dispatch: Dispatch<any>): void;
|
||||
propagateInsert?(doc: Document, dispatch: Dispatch<any>): void;
|
||||
propagateUpdate?(doc: Document, dispatch: Dispatch<any>): void;
|
||||
handleResponse?(err: Error, data: any, errorCallback: (err: Error) => void): void;
|
||||
queue?(...args: any[]): any;
|
||||
docs?: any;
|
||||
actions: {
|
||||
remove(doc: Document): Action;
|
||||
update(doc: Document): Action;
|
||||
insert(doc: Document): Action;
|
||||
};
|
||||
}
|
||||
|
||||
export default function PouchMiddlewareFactory(paths?: Path[] | Path): Middleware;
|
||||
export default function PouchMiddlewareFactory<T = {[field: string]: any}>(paths?: Array<Path<T>> | Path<T>): Middleware;
|
||||
|
||||
@@ -4,19 +4,22 @@ import PouchDB = require('pouchdb');
|
||||
|
||||
const types = {
|
||||
DELETE_TODO: 'delete-todo',
|
||||
BATCH_INSERT_TODO: 'batch-insert-todo',
|
||||
INSERT_TODO: 'insert-todo',
|
||||
UPDATE_TODO: 'update-todo'
|
||||
};
|
||||
|
||||
const path: Path = {
|
||||
const path: Path<{}> = {
|
||||
path: "/test",
|
||||
db: new PouchDB('test'),
|
||||
actions: {
|
||||
remove: doc => ({ type: types.DELETE_TODO, id: doc._id }),
|
||||
batchInsert: doc => ({ type: types.BATCH_INSERT_TODO, todo: doc }),
|
||||
insert: doc => ({ type: types.INSERT_TODO, todo: doc }),
|
||||
update: doc => ({ type: types.UPDATE_TODO, todo: doc }),
|
||||
}
|
||||
},
|
||||
initialBatchDispatched: (error?: Error) => {},
|
||||
};
|
||||
|
||||
const middleware: redux.Middleware = makePouchMiddleware(path);
|
||||
const middleware: redux.Middleware = makePouchMiddleware<{}>(path);
|
||||
const otherMiddleware: redux.Middleware = makePouchMiddleware([path, path, path]);
|
||||
|
||||
Reference in New Issue
Block a user