[pouch-redux-middleware] v1.2 (#38277)

* Updating pouch-redux-middleware for v1.2

* Fixing spacing
This commit is contained in:
FaithForHumans
2019-09-24 18:42:48 -05:00
committed by Ben Lichtman
parent 2f7e7ab580
commit 56b659e0f0
2 changed files with 29 additions and 26 deletions

View File

@@ -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;

View File

@@ -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]);