Skip to content

Instantly share code, notes, and snippets.

@zilveer
Forked from ThinkingJoules/getCheckUnique.js
Created June 15, 2022 16:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zilveer/70b95ab9e9b5b7b914e8fece8dcf1c58 to your computer and use it in GitHub Desktop.
Save zilveer/70b95ab9e9b5b7b914e8fece8dcf1c58 to your computer and use it in GitHub Desktop.
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