Skip to content

Instantly share code, notes, and snippets.

@bitnom
Created July 25, 2019 15:57
Show Gist options
  • Save bitnom/d1e50b29d00f20e312713e6bc7c0153a to your computer and use it in GitHub Desktop.
Save bitnom/d1e50b29d00f20e312713e6bc7c0153a to your computer and use it in GitHub Desktop.
gun setu() - add to set only if unique
function setu(node, item){
let unique = true
let comparison = 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
}
}
}
};
let check = function(){
if(unique){
node.set(item)
}
};
node.map().once(comparison.bind(this)).then(check.bind(this))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment