Skip to content

Commit bb72f22

Browse files
Update config
1 parent 844f17a commit bb72f22

File tree

1 file changed

+41
-44
lines changed

1 file changed

+41
-44
lines changed

js/configuration.js

Lines changed: 41 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -85,44 +85,40 @@ const DEFAULT_CONFIGURATIONS = {
8585
}
8686
};
8787

88-
const PROXY_GET = function(obj, key) {
89-
if (!key) {
90-
return null;
91-
}
92-
93-
for (const k of key.split(".")) {
94-
obj = obj[k];
95-
if (!obj) {
96-
break;
88+
const PROXY_HANDLER = {
89+
get: function(obj, key) {
90+
if (!key) {
91+
return null;
9792
}
98-
}
9993

100-
return obj;
101-
};
94+
for (const k of key.split(".")) {
95+
obj = obj[k];
96+
if (!obj) {
97+
break;
98+
}
99+
}
102100

103-
const PROXT_SET = function(obj, key, val) {
104-
if (!key) {
105-
return false;
106-
}
101+
return obj;
102+
},
103+
set: function(obj, key, val) {
104+
if (!key) {
105+
return false;
106+
}
107107

108-
const keys = key.split(".");
109-
const lastKey = keys[keys.length - 1];
108+
const keys = key.split(".");
109+
const lastKey = keys[keys.length - 1];
110110

111-
for (let i = 0; i < keys.length - 1; i++) {
112-
if (!obj[keys[i]]) {
113-
obj[keys[i]] = {};
111+
for (let i = 0; i < keys.length - 1; i++) {
112+
if (!obj[keys[i]]) {
113+
obj[keys[i]] = {};
114+
}
115+
obj = obj[keys[i]];
114116
}
115-
obj = obj[keys[i]];
116-
}
117-
118-
obj[lastKey] = val;
119117

120-
return true;
121-
};
118+
obj[lastKey] = val;
122119

123-
const PROXY_HANDLER = {
124-
get: PROXY_GET,
125-
set: PROXT_SET
120+
return true;
121+
}
126122
};
127123

128124
const LEGAL_VALUES = new Proxy({
@@ -134,26 +130,27 @@ const LEGAL_VALUES = new Proxy({
134130
}
135131
}, PROXY_HANDLER);
136132

133+
var CONFIGURATION = null;
134+
var LOADED_CONFIGURATION = null;
135+
137136
const configuration = {
138-
CONFIGURATION: null,
139-
LOADED_CONFIGURATION: null,
140137
load() {
141138
configuration.getConfig();
142139
},
143140
getConfig() {
144-
if (!configuration.CONFIGURATION) {
145-
configuration.CONFIGURATION = new Proxy(JSON.parse(JSON.stringify(DEFAULT_CONFIGURATIONS.default)), {
146-
get: PROXY_GET,
141+
if (!CONFIGURATION) {
142+
CONFIGURATION = new Proxy(JSON.parse(JSON.stringify(DEFAULT_CONFIGURATION)), {
143+
get: PROXY_HANDLER.get,
147144
set: function(obj, key, val) {
148145
if (LEGAL_VALUES[key] && !LEGAL_VALUES[key].includes(val)) {
149146
return true;
150147
}
151148

152-
if (PROXY_GET(obj, key) === val) {
149+
if (PROXY_HANDLER.get(obj, key) === val) {
153150
return true;
154151
}
155152

156-
PROXT_SET(obj, key, val);
153+
PROXY_HANDLER.set(obj, key, val);
157154

158155
if (key === "style") {
159156
obj.styleOptions = DEFAULT_CONFIGURATIONS[val].styleOptions;
@@ -164,21 +161,21 @@ const configuration = {
164161
return true;
165162
}
166163
});
167-
configuration.merge(configuration.CONFIGURATION, configuration.getLoadedConfig());
164+
configuration.merge(CONFIGURATION, configuration.getLoadedConfig());
168165
}
169-
return configuration.CONFIGURATION;
166+
return CONFIGURATION;
170167
},
171168
getLoadedConfig() {
172-
if (!configuration.LOADED_CONFIGURATION) {
173-
configuration.LOADED_CONFIGURATION = new Proxy({}, PROXY_HANDLER);
174-
for (const key of configuration.getKeys(DEFAULT_CONFIGURATIONS.default)) {
169+
if (!LOADED_CONFIGURATION) {
170+
LOADED_CONFIGURATION = new Proxy({}, PROXY_HANDLER);
171+
for (const key of configuration.getKeys(DEFAULT_CONFIGURATION)) {
175172
const val = query.get(`${ls.PREFIX}${key}`) || ls.get(key);
176173
if (val) {
177-
configuration.LOADED_CONFIGURATION[key] = val;
174+
LOADED_CONFIGURATION[key] = val;
178175
}
179176
}
180177
}
181-
return configuration.LOADED_CONFIGURATION;
178+
return LOADED_CONFIGURATION;
182179
},
183180
get(key) {
184181
const config = configuration.getConfig();

0 commit comments

Comments
 (0)