Skip to content

Instantly share code, notes, and snippets.

@bitnom
Created July 18, 2019 15:24
Show Gist options
  • Save bitnom/c15416f63c2d91e3c1b7d01ee476229d to your computer and use it in GitHub Desktop.
Save bitnom/c15416f63c2d91e3c1b7d01ee476229d to your computer and use it in GitHub Desktop.
gun set if unique (Working)
function setu(node, item){
let unique = true
node.map().once(function (data) {
let aProps = Object.getOwnPropertyNames(data);
let bProps = Object.getOwnPropertyNames(item);
// number of properties
if ((aProps.length-1) === bProps.length) {
for (let i = 1; i < aProps.length; i++) {
let propName = aProps[i];
// values of same property
if (data[propName] === item[propName]) {
unique = false
}
}
}
})
.then(function(){
if(unique){
node.set(item)
}
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment