-
-
Save zilveer/70b95ab9e9b5b7b914e8fece8dcf1c58 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function getList(idxSoul,cb){ | |
let listOfSouls = {} | |
let soulsToCheckAgainstUnique = [] | |
gun.get(idxSoul).once(function(data){ | |
if(data === undefined){cb.call(cb,listOfSouls); return}//for loop would error if not stopped | |
for (const soul in data) { | |
if(soul === '_')continue | |
if(data[soul] !== null){//not Deleted | |
//this means `false` will pass through, so archived items will still keep increment and unique values enforced | |
soulsToCheckAgainstUnique.push(soul) | |
} | |
} | |
let toGet = soulsToCheckAgainstUnique.length | |
for (const soul of soulsToCheckAgainstUnique) { | |
gun.get(soul).once(function(node){ | |
toGet-- | |
let clean = JSON.parse(JSON.stringify(node)) | |
delete clean['_'] //get rid of gun meta data | |
listOfSouls[souls] = clean | |
if(!toGet){ | |
cb.call(cb,listOfSouls) | |
} | |
}) | |
} | |
}) | |
} | |
//now we call it, and 'list' should be all nodes | |
getList(idxSoul,function(list){ | |
list = list | |
for (const soul in list) { | |
const node = list[soul]; | |
//validate here | |
} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment