Skip to content

Instantly share code, notes, and snippets.

@ThinkingJoules
Created July 18, 2019 15:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ThinkingJoules/37d3ebf4a08b6ccc6df403eb1e24ff25 to your computer and use it in GitHub Desktop.
Save ThinkingJoules/37d3ebf4a08b6ccc6df403eb1e24ff25 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