Skip to content

Commit 7a64539

Browse files
shiv-tyagitridge
authored andcommitted
static: js: store reference to option object directly in dictionaries
Instead of storing the indices of option object in the dictionaries, store its reference directly
1 parent fa7d186 commit 7a64539

File tree

1 file changed

+5
-18
lines changed

1 file changed

+5
-18
lines changed

static/js/add_build.js

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,9 @@ const Features = (() => {
66
function resetDictionaries() {
77
defines_dictionary = {}; // clear old dictionary
88
labels_dictionary = {}; // clear old dictionary
9-
features.forEach((category, cat_idx) => {
10-
category['options'].forEach((option, opt_idx) => {
11-
defines_dictionary[option.define] = labels_dictionary[option.label] = {
12-
'category_index' : cat_idx,
13-
'option_index' : opt_idx,
14-
};
9+
features.forEach((category) => {
10+
category['options'].forEach((option) => {
11+
defines_dictionary[option.define] = labels_dictionary[option.label] = option;
1512
});
1613
});
1714
}
@@ -39,19 +36,11 @@ const Features = (() => {
3936
}
4037

4138
function getByDefine(define) {
42-
let dict_value = defines_dictionary[define];
43-
if (dict_value == undefined) {
44-
return null;
45-
}
46-
return features[dict_value['category_index']]['options'][dict_value['option_index']];
39+
return defines_dictionary[define];
4740
}
4841

4942
function getByLabel(label) {
50-
let dict_value = labels_dictionary[label];
51-
if (dict_value == undefined) {
52-
return null;
53-
}
54-
return features[dict_value['category_index']]['options'][dict_value['option_index']];
43+
return labels_dictionary[label];
5544
}
5645

5746
function updateDefaults(defines_array) {
@@ -62,8 +51,6 @@ const Features = (() => {
6251
let select_opt = (defines_array[i][0] != '!');
6352
let sanitised_define = (select_opt ? defines_array[i] : defines_array[i].substring(1)); // this removes the leading '!' from define if it contatins
6453
if (getByDefine(sanitised_define)) {
65-
let cat_idx = defines_dictionary[sanitised_define]['category_index'];
66-
let opt_idx = defines_dictionary[sanitised_define]['option_index'];
6754
getByDefine(sanitised_define).default = select_opt ? 1 : 0;
6855
}
6956
}

0 commit comments

Comments
 (0)