Kind of still new to JS/TS and the conventions that come along with them. I wrote this piece of code today and thought it just kind of looked wrong.
tldr: Look up depth-3 child using hierarchical-ordered names, while performing null-checks.
public loadChildChild(parentName: string, childName: string, childchildName: string) {
var parent = myCollection.items.find(i => i.name === parentName)
if(parent === undefined){
console.error(`${parentName} not found in collection`);
}
else{
var child = parent.children.find(c => c.name === childName)
if(child === undefined){
console.error(`${childName} not found in ${parentName}`);
}
else{
var childChild = child.children.find(c => c.name === childChildName))
if(childChild == undefined){
console.error(`${childChildName} not found in ${parentName}>${childName}`)
}
else {
this.selectedItem = childChild;
}
}
}
}
To me this seems like its a pain to read, and that there's probably some standard convention - or JS/TS magic for cleaning this up.