Skip to content

Commit 043496c

Browse files
committed
implement aliases for getVars method
1 parent 81825d4 commit 043496c

2 files changed

Lines changed: 32 additions & 3 deletions

File tree

lib/core.js

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -943,9 +943,20 @@
943943
}
944944
}
945945
}
946-
} else if (r.method.name === "getVars") {
947-
for(var key in r.data) {
948-
var v = r.data[key];
946+
} else if (r.method.name === "getVars" || r.method.name in pluginUtils.GET_VARS_METHODS) {
947+
948+
var result_data = r.data;
949+
950+
// Set specific alias as key.
951+
if (r.method.name in pluginUtils.GET_VARS_METHODS) {
952+
var key = pluginUtils.GET_VARS_METHODS[r.method.name];
953+
result_data = {
954+
[key]: r.data
955+
};
956+
}
957+
958+
for(var key in result_data) {
959+
var v = result_data[key];
949960

950961
// TODO: work with arrays?
951962
if (v !== '' && v !== null && ((typeof v === 'string' && !/^\s+$/.test(v)) || typeof v === 'number' || typeof v === 'object')) {

lib/loader/utils.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,24 @@
4343
"prepareLink"
4444
];
4545

46+
const GET_VARS_ALIAS = [
47+
'signals',
48+
'policy',
49+
'sources'
50+
];
51+
52+
export const GET_VARS_METHODS = {
53+
// getSignals: signals
54+
};
55+
56+
// Adds `GET_VARS_ALIAS` to `PLUGIN_METHODS` as `signals` => `getSignals`.
57+
// Fills `GET_VARS_METHODS` with proper key values.
58+
GET_VARS_ALIAS.forEach(alias => {
59+
const methodName = `get${alias[0].toUpperCase()}${alias.substring(1)}`;
60+
PLUGIN_METHODS.push(methodName);
61+
GET_VARS_METHODS[methodName] = alias;
62+
});
63+
4664
export const PLUGIN_FIELDS = PLUGIN_METHODS.concat([
4765
"mixins"
4866
]);

0 commit comments

Comments
 (0)