Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
getListOfArrayKey(tree, key) {
let result = [];
crawl(
tree,
node => {
if (node.meta && node.meta[key]) {
// check if it's a comma separated string instead of an array, and split it up
const arr =
node.meta[key][0] && node.meta[key][0].indexOf(',') > -1
? node.meta[key][0].split(',')
: node.meta[key];
result = this.mergeArray([result, arr]);
}
},
{ getChildren: node => node.items }
);
return this.uniqueArray(result);
getVideoById(tree, videoId) {
let result;
crawl(
tree,
(node, context) => {
if (node.type === 'video' && node.meta && node.meta.id === videoId) {
result = node;
// generate path to show breadcrumb and add to node
node.path = context.cursor.stack.xs.reduce((result, item) => {
if (item.node && item.node.meta) {
result.push(item.node.meta.title);
}
return result;
}, []);
context.break();
}
},
const setNewMetaInTree = (tree, newMeta) => {
crawl(
tree,
(node, context) => {
if (node.meta && node.meta.id === newMeta.id) {
const newNode = node;
newNode.meta = newMeta;
context.parent.items[context.index] = newNode;
context.replace(newNode);
}
},
{ getChildren: node => node.items }
);
return tree;
};
const setNewMetaInTree = (tree, newMeta) => {
crawl(
tree,
(node, context) => {
if (node.meta && node.meta.id === newMeta.id) {
const newNode = node;
newNode.meta = newMeta;
context.parent.items[context.index] = newNode;
context.replace(newNode);
}
},
{ getChildren: node => node.items }
);
return tree;
};