minor fix + simplified .exists(..)...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2022-10-26 00:38:52 +03:00
parent 6ab0aa4fd5
commit 0df1919259

View File

@ -206,10 +206,21 @@ module.BaseStore = {
// -> <normalized-path> // -> <normalized-path>
// -> false // -> false
// //
// XXX might be a good idea to cache this... // XXX INDEXED...
exists: async function(path){
var {path, args} =
pwpath.splitArgs(
pwpath.sanitize(path, 'string'))
//return new Set(await this.paths).has(path) ?
//return (await this.paths).indexOf(path) != -1 ?
return (await this.paths).includes(path) ?
pwpath.joinArgs(path, args)
: undefined },
/*/
__exists__: async function(path){ __exists__: async function(path){
return path in this.data return path in this.data
&& path }, && path },
// XXX might be a good idea to cache this...
exists: async function(path){ exists: async function(path){
var {path, args} = var {path, args} =
pwpath.splitArgs( pwpath.splitArgs(
@ -235,6 +246,7 @@ module.BaseStore = {
if(typeof(res) != 'string'){ if(typeof(res) != 'string'){
return false } return false }
return pwpath.joinArgs(res, args) }, return pwpath.joinArgs(res, args) },
//*/
// find the closest existing alternative path... // find the closest existing alternative path...
find: async function(path, strict=false){ find: async function(path, strict=false){
var {path, args} = pwpath.splitArgs(path) var {path, args} = pwpath.splitArgs(path)
@ -500,8 +512,7 @@ module.BaseStore = {
path = await this.exists(path) path = await this.exists(path)
if(typeof(path) == 'string'){ if(typeof(path) == 'string'){
await this.__delete__(path) await this.__delete__(path)
this.index('remove', path) this.index('remove', path) }
this.onDelete(path) }
return this }, return this },
delete: types.event.Event('delete', delete: types.event.Event('delete',
function(handler, path){ function(handler, path){