informa-db.js
Advanced tools
Comparing version 2.3.2 to 2.3.3
@@ -23,2 +23,26 @@ import DbUtils from './utils.js'; // eslint-disable-line import/extensions | ||
genProxy(data) { | ||
return new Proxy(data, { | ||
set: (obj, prop, val) => { | ||
obj[prop] = val; | ||
if (this.saveOnChange) { | ||
this.update(); | ||
} | ||
return true; | ||
}, | ||
deleteProperty: (obj, prop) => { | ||
delete obj[prop]; | ||
if (this.saveOnChange) { | ||
this.update(); | ||
} | ||
return true; | ||
}, | ||
get: (obj, prop) => ( | ||
typeof obj[prop] === 'object' && obj[prop] | ||
? this.genProxy(obj[prop]) | ||
: obj[prop] | ||
), | ||
}); | ||
} | ||
/** | ||
@@ -50,3 +74,3 @@ * async Updates the file/db from this.readOnlyValue | ||
get value() { | ||
return DbUtils.genProxy(this.readOnlyValue, this.saveOnChange, this.update); | ||
return this.genProxy(this.readOnlyValue); | ||
} | ||
@@ -53,0 +77,0 @@ } |
{ | ||
"name": "informa-db.js", | ||
"version": "2.3.2", | ||
"version": "2.3.3", | ||
"description": "DataBases made easier", | ||
@@ -5,0 +5,0 @@ "main": "server.js", |
@@ -24,2 +24,26 @@ const fs = require('fs'); | ||
genProxy(data, saveOnChange, update) { | ||
return new Proxy(data, { | ||
set: (obj, prop, val) => { | ||
obj[prop] = val; | ||
if (saveOnChange) { | ||
update(); | ||
} | ||
return true; | ||
}, | ||
deleteProperty: (obj, prop) => { | ||
delete obj[prop]; | ||
if (saveOnChange) { | ||
update(); | ||
} | ||
return true; | ||
}, | ||
get: (obj, prop) => ( | ||
typeof obj[prop] === 'object' && obj[prop] | ||
? this.genProxy(obj[prop]) | ||
: obj[prop] | ||
), | ||
}); | ||
} | ||
/** | ||
@@ -51,3 +75,3 @@ * async Updates the file/db from this.readOnlyValue | ||
get value() { | ||
return DbUtils.genProxy(this.readOnlyValue, this.saveOnChange, this.update); | ||
return this.genProxy(this.readOnlyValue); | ||
} | ||
@@ -54,0 +78,0 @@ } |
23
utils.js
@@ -6,25 +6,2 @@ export default { | ||
}, | ||
genProxy(data, saveOnChange, update) { | ||
return new Proxy(data, { | ||
set: (obj, prop, val) => { | ||
obj[prop] = val; | ||
if (saveOnChange) { | ||
update(); | ||
} | ||
return true; | ||
}, | ||
deleteProperty: (obj, prop) => { | ||
delete obj[prop]; | ||
if (saveOnChange) { | ||
update(); | ||
} | ||
return true; | ||
}, | ||
get: (obj, prop) => ( | ||
typeof obj[prop] === 'object' && obj[prop] | ||
? this.genProxy(obj[prop]) | ||
: obj[prop] | ||
), | ||
}); | ||
}, | ||
}; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
10091
163