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:
parent
e29e41514a
commit
fad4db8a40
@ -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 },
|
||||
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;
|
||||
};
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user