You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@flagon.apache.org by rf...@apache.org on 2019/09/26 00:11:44 UTC
[incubator-flagon-useralejs] 01/03: Moved SessionId initialization
to a one-time run in getInitialSettings. Changed to camelCase. Removed
weird JSON.parse check
This is an automated email from the ASF dual-hosted git repository.
rf pushed a commit to branch FLAGON-434
in repository https://gitbox.apache.org/repos/asf/incubator-flagon-useralejs.git
commit e545d8ce81beaa690d3ba71668ecb78a3da05aaf
Author: Rob Foley <ro...@gmail.com>
AuthorDate: Wed Sep 25 19:54:45 2019 -0400
Moved SessionId initialization to a one-time run in getInitialSettings. Changed to camelCase. Removed weird JSON.parse check
---
src/getInitialSettings.js | 21 ++++++++++++---------
1 file changed, 12 insertions(+), 9 deletions(-)
diff --git a/src/getInitialSettings.js b/src/getInitialSettings.js
index d55806d..987d5c8 100644
--- a/src/getInitialSettings.js
+++ b/src/getInitialSettings.js
@@ -3,19 +3,19 @@
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
+ * (the 'License'); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
+ * distributed under the License is distributed on an 'AS IS' BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-var SessionId = getSessionId("userAleSessionId", 'session_' + String(Date.now()));
+ var sessionId = null;
/**
* Extracts the initial configuration settings from the
@@ -25,6 +25,10 @@ var SessionId = getSessionId("userAleSessionId", 'session_' + String(Date.now())
export function getInitialSettings() {
var settings = {};
+ if (sessionId === null) {
+ sessionId = getSessionId('userAleSessionId', 'session_' + String(Date.now()));
+ }
+
var script = document.currentScript || (function () {
var scripts = document.getElementsByTagName('script');
return scripts[scripts.length - 1];
@@ -43,7 +47,7 @@ export function getInitialSettings() {
settings.toolName = get('data-tool') || null;
settings.userFromParams = get('data-user-from-params') || null;
settings.time = timeStampScale(document.createEvent('CustomEvent'));
- settings.sessionID = get('data-session') || SessionId;
+ settings.sessionID = get('data-session') || sessionId;
return settings;
}
@@ -55,13 +59,12 @@ export function getInitialSettings() {
*
*/
export function getSessionId(sessionKey, value){
- if (JSON.parse(window.sessionStorage.getItem(sessionKey) === null)) {
- var storedSession = value;
+ if (window.sessionStorage.getItem(sessionKey) === null) {
window.sessionStorage.setItem(sessionKey, JSON.stringify(value));
- } else {
- storedSession = JSON.parse(window.sessionStorage.getItem(sessionKey));
+ return JSON.stringify(value);
}
- return storedSession;
+
+ return JSON.parse(window.sessionStorage.getItem(sessionKey));
}