Skip to content

Commit

Permalink
Use map for deduping rather than lodash
Browse files Browse the repository at this point in the history
  • Loading branch information
sabarasaba committed Nov 27, 2024
1 parent eaa4488 commit 8e14455
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/plugins/console/public/lib/autocomplete/engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,22 +119,24 @@ export function populateContext(tokenPath, context, editor, includeAutoComplete,
editor
);
if (includeAutoComplete) {
let autoCompleteSet = [];
let autoCompleteSet = new Map();
_.each(walkStates, function (ws) {
const contextForState = passThroughContext(context, ws.contextExtensionList);
_.each(ws.components, function (component) {
_.each(component.getTerms(contextForState, editor), function (term) {
if (!_.isObject(term)) {
term = { name: term };
}
// Make sure we don't have duplicates
if (!_.find(autoCompleteSet, { name: term.name })) {
autoCompleteSet.push(term);

// Add the term to the autoCompleteSet if it doesn't already exist
if (!autoCompleteSet.has(term.name)) {
autoCompleteSet.set(term.name, term);
}
});
});
});
autoCompleteSet = _.uniq(autoCompleteSet);
// Convert Map values to an array of objects
autoCompleteSet = Array.from(autoCompleteSet.values());
context.autoCompleteSet = autoCompleteSet;
}

Expand Down

0 comments on commit 8e14455

Please sign in to comment.