Allow some functions to be overloaded.

With Type.delete, we call the object's delete in case it is overloaded.
This commit is contained in:
Timothy Farrell 2018-05-23 05:05:04 -05:00
parent e29e41514a
commit fad4db8a40

View File

@ -56,8 +56,7 @@ export function PouchORM(PouchDB) {
async function _delete(id) {
try {
const doc = await find(id);
doc._deleted = true;
await _db.put(doc);
await doc.delete();
} catch (e) {
if (e.status !== 404) {
throw e;
@ -83,17 +82,31 @@ export function PouchORM(PouchDB) {
_baseSelector: { value: _baseSelector }
});
Object.defineProperties(cls, {
const methods = {
getOrCreate: { value: getOrCreate },
find: { value: find },
index: { value: _index },
delete: { value: _delete },
subscribe: { value: watch },
db: { value: _db },
name: { value: name },
prefix: { value: prefix },
selector: { value: _baseSelector }
});
subscribe: { value: watch }
};
Object.defineProperties(
cls,
Object.assign(
{
db: { value: _db },
name: { value: name },
prefix: { value: prefix },
selector: { value: _baseSelector }
},
Object.entries(methods)
.filter(([name, obj]) => cls[name] === undefined)
.reduce((acc, [name, obj]) => {
acc[name] = obj;
return acc;
}, {})
)
);
return cls;
};