You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@flagon.apache.org by po...@apache.org on 2022/03/25 06:29:24 UTC
[incubator-flagon-useralejs] 02/04: improve configure efficiency
This is an automated email from the ASF dual-hosted git repository.
poorejc pushed a commit to branch setupStartStopRefactor
in repository https://gitbox.apache.org/repos/asf/incubator-flagon-useralejs.git
commit 5378696f9bbff007d1a214fe38e381e7f17a50d4
Author: giterdone77 <kb...@gmail.com>
AuthorDate: Wed Mar 23 22:11:41 2022 -0400
improve configure efficiency
---
src/configure.js | 43 ++++++++++++++++++++++---------------------
1 file changed, 22 insertions(+), 21 deletions(-)
diff --git a/src/configure.js b/src/configure.js
index 1b25a30..6be8fec 100644
--- a/src/configure.js
+++ b/src/configure.js
@@ -22,20 +22,21 @@
* @param {Object} newConfig Configuration object to merge into the current config.
*/
export function configure(config, newConfig) {
- const configAutostart = config['autostart'];
- const newConfigAutostart = newConfig['autostart'];
- Object.keys(newConfig).forEach(function(option) {
- if (option === 'userFromParams') {
- const userId = getUserIdFromParams(newConfig[option]);
- if (userId) {
- config.userId = userId;
- }
+ const configAutostart = config['autostart'];
+ const newConfigAutostart = newConfig['autostart'];
+ Object.keys(newConfig).forEach(function (option) {
+ if (option === 'userFromParams') {
+ const userId = getUserIdFromParams(newConfig[option]);
+ if (userId) {
+ config.userId = userId;
+ }
+ }
+ config[option] = newConfig[option];
+ }
+ )
+ if (configAutostart === false || newConfigAutostart === false) {
+ config['autostart'] = false;
}
- config[option] = newConfig[option];
- if (configAutostart === false || newConfigAutostart === false){
- config['autostart'] = false;
- }
- });
}
/**
@@ -44,13 +45,13 @@ export function configure(config, newConfig) {
* @return {string|null} The extracted/decoded userid, or null if none is found.
*/
export function getUserIdFromParams(param) {
- const userField = param;
- const regex = new RegExp('[?&]' + userField + '(=([^&#]*)|&|#|$)');
- const results = window.location.href.match(regex);
+ const userField = param;
+ const regex = new RegExp('[?&]' + userField + '(=([^&#]*)|&|#|$)');
+ const results = window.location.href.match(regex);
- if (results && results[2]) {
- return decodeURIComponent(results[2].replace(/\+/g, ' '));
- } else {
- return null;
- }
+ if (results && results[2]) {
+ return decodeURIComponent(results[2].replace(/\+/g, ' '));
+ } else {
+ return null;
+ }
}