Created
July 25, 2019 15:57
-
-
Save bitnom/d1e50b29d00f20e312713e6bc7c0153a to your computer and use it in GitHub Desktop.
gun setu() - add to set only if unique
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 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