You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@flagon.apache.org by un...@apache.org on 2023/05/05 17:24:23 UTC

[flagon-useralejs] 02/04: Fixed callbacks in example page

This is an automated email from the ASF dual-hosted git repository.

unclegedd pushed a commit to branch test
in repository https://gitbox.apache.org/repos/asf/flagon-useralejs.git

commit e7619ae29b92c11753979c8f532df83f90cf2153
Author: Jason Young <ja...@protonmail.com>
AuthorDate: Wed Mar 29 18:23:51 2023 -0700

    Fixed callbacks in example page
---
 build/UserALEWebExtension/background.js | 16 ++++++++
 build/UserALEWebExtension/content.js    | 59 +++++++++++++--------------
 build/userale-2.3.0.js                  | 72 +++++++++++++++++++--------------
 build/userale-2.3.0.min.js              |  2 +-
 example/index.js                        | 25 ++++++++----
 src/main.js                             |  1 +
 src/packageLogs.js                      |  4 +-
 7 files changed, 106 insertions(+), 73 deletions(-)

diff --git a/build/UserALEWebExtension/background.js b/build/UserALEWebExtension/background.js
index abd9d13..8fbb7e5 100644
--- a/build/UserALEWebExtension/background.js
+++ b/build/UserALEWebExtension/background.js
@@ -307,6 +307,22 @@ function createVersionParts(count) {
     return output;
 }
 
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * 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 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,
+ * 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.
+ */
 detect();
 
 /**
diff --git a/build/UserALEWebExtension/content.js b/build/UserALEWebExtension/content.js
index d0689d1..06b518b 100644
--- a/build/UserALEWebExtension/content.js
+++ b/build/UserALEWebExtension/content.js
@@ -415,9 +415,22 @@ function createVersionParts(count) {
     return output;
 }
 
-function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new T [...]
-function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
-function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * 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 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,
+ * 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 browser$1 = detect();
 var logs$1;
 var config$1;
@@ -553,22 +566,14 @@ function packageCustomLog(customLog, detailFcn, userAction) {
     'sessionID': config$1.sessionID
   };
   var log = Object.assign(metaData, customLog);
-  var _iterator = _createForOfIteratorHelper(cbHandlers.values()),
-    _step;
-  try {
-    for (_iterator.s(); !(_step = _iterator.n()).done;) {
-      var func = _step.value;
-      if (typeof func === 'function') {
-        log = func(log, null);
-        if (!log) {
-          return false;
-        }
+  for (var _i2 = 0, _Object$values2 = Object.values(cbHandlers); _i2 < _Object$values2.length; _i2++) {
+    var func = _Object$values2[_i2];
+    if (typeof func === 'function') {
+      log = func(log, null);
+      if (!log) {
+        return false;
       }
     }
-  } catch (err) {
-    _iterator.e(err);
-  } finally {
-    _iterator.f();
   }
   logs$1.push(log);
   return true;
@@ -633,22 +638,14 @@ function packageIntervalLog(e) {
       'useraleVersion': config$1.useraleVersion,
       'sessionID': config$1.sessionID
     };
-    var _iterator2 = _createForOfIteratorHelper(cbHandlers.values()),
-      _step2;
-    try {
-      for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
-        var func = _step2.value;
-        if (typeof func === 'function') {
-          intervalLog = func(intervalLog, null);
-          if (!intervalLog) {
-            return false;
-          }
+    for (var _i3 = 0, _Object$values3 = Object.values(cbHandlers); _i3 < _Object$values3.length; _i3++) {
+      var func = _Object$values3[_i3];
+      if (typeof func === 'function') {
+        intervalLog = func(intervalLog, null);
+        if (!intervalLog) {
+          return false;
         }
       }
-    } catch (err) {
-      _iterator2.e(err);
-    } finally {
-      _iterator2.f();
     }
     logs$1.push(intervalLog);
 
diff --git a/build/userale-2.3.0.js b/build/userale-2.3.0.js
index fd8a994..d1a22fb 100644
--- a/build/userale-2.3.0.js
+++ b/build/userale-2.3.0.js
@@ -400,9 +400,22 @@
       return output;
   }
 
-  function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new [...]
-  function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
-  function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
+  /*
+   * Licensed to the Apache Software Foundation (ASF) under one or more
+   * 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 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,
+   * 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 browser = detect();
   var logs$1;
   var config$1;
@@ -440,6 +453,18 @@
     return cbHandlers;
   }
 
+  /**
+   * Removes callbacks by name.
+   * @param  {String[]} targetKeys A list of names of functions to remove.
+   */
+  function removeCallbacks(targetKeys) {
+    targetKeys.forEach(function (key) {
+      if (Object.hasOwn(cbHandlers, key)) {
+        delete cbHandlers[key];
+      }
+    });
+  }
+
   /**
    * Assigns the config and log container to be used by the logging functions.
    * @param  {Array} newLogs   Log container.
@@ -538,22 +563,14 @@
       'sessionID': config$1.sessionID
     };
     var log = Object.assign(metaData, customLog);
-    var _iterator = _createForOfIteratorHelper(cbHandlers.values()),
-      _step;
-    try {
-      for (_iterator.s(); !(_step = _iterator.n()).done;) {
-        var func = _step.value;
-        if (typeof func === 'function') {
-          log = func(log, null);
-          if (!log) {
-            return false;
-          }
+    for (var _i2 = 0, _Object$values2 = Object.values(cbHandlers); _i2 < _Object$values2.length; _i2++) {
+      var func = _Object$values2[_i2];
+      if (typeof func === 'function') {
+        log = func(log, null);
+        if (!log) {
+          return false;
         }
       }
-    } catch (err) {
-      _iterator.e(err);
-    } finally {
-      _iterator.f();
     }
     logs$1.push(log);
     return true;
@@ -618,22 +635,14 @@
         'useraleVersion': config$1.useraleVersion,
         'sessionID': config$1.sessionID
       };
-      var _iterator2 = _createForOfIteratorHelper(cbHandlers.values()),
-        _step2;
-      try {
-        for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
-          var func = _step2.value;
-          if (typeof func === 'function') {
-            intervalLog = func(intervalLog, null);
-            if (!intervalLog) {
-              return false;
-            }
+      for (var _i3 = 0, _Object$values3 = Object.values(cbHandlers); _i3 < _Object$values3.length; _i3++) {
+        var func = _Object$values3[_i3];
+        if (typeof func === 'function') {
+          intervalLog = func(intervalLog, null);
+          if (!intervalLog) {
+            return false;
           }
         }
-      } catch (err) {
-        _iterator2.e(err);
-      } finally {
-        _iterator2.f();
       }
       logs$1.push(intervalLog);
 
@@ -1153,6 +1162,7 @@
   exports.options = options;
   exports.packageCustomLog = packageCustomLog;
   exports.packageLog = packageLog;
+  exports.removeCallbacks = removeCallbacks;
   exports.start = start;
   exports.stop = stop;
   exports.version = version;
diff --git a/build/userale-2.3.0.min.js b/build/userale-2.3.0.min.js
index 82396de..6710907 100644
--- a/build/userale-2.3.0.min.js
+++ b/build/userale-2.3.0.min.js
@@ -16,4 +16,4 @@
  * @preserved
  */
 
-!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).userale={})}(this,(function(e){"use strict";function t(e){return t="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},t(e)}var n="2.3.0",o=null;fu [...]
+!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).userale={})}(this,(function(e){"use strict";function t(e){return t="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},t(e)}var n="2.3.0",o=null;fu [...]
diff --git a/example/index.js b/example/index.js
index 11af64a..44bb1e2 100644
--- a/example/index.js
+++ b/example/index.js
@@ -38,7 +38,10 @@ window.userale.addCallbacks({
     filter(log) {
         var type_array = ['mouseup', 'mouseover', 'mousedown', 'keydown', 'dblclick', 'blur', 'focus', 'input', 'wheel'];
         var logType_array = ['interval'];
-        return !type_array.includes(log.type) && !logType_array.includes(log.logType);
+        if(type_array.includes(log.type) || logType_array.includes(log.logType)) {
+            return false;
+        }
+        return log;
     }
 });
 
@@ -47,13 +50,19 @@ window.userale.addCallbacks({
  * the 'map' API allows you to add or modify new fields to your logs
  * this example works with the "Click Me!" button at the top of index.html
  */
-window.userale.addCallbacks({
-    map(log, e) {
-        if(e && e.type === 'click' && e.target.innerHTML === 'Click Me!') {
-            return Object.assign({}, log, { logType: 'custom', customLabel: 'map & packageLog Example' });
-        }
-
-        return log;
+document.addEventListener('click', function(e){
+    if (e.target.innerHTML === 'Click Me!') {
+        window.userale.addCallbacks({
+            map(log) {
+                return Object.assign({}, log, { logType: 'custom', customLabel: 'map & packageLog Example' });
+            }
+        });
+        window.userale.packageLog(e, window.userale.details(window.userale.options(),e.type));
+        /**you'll want to reset the map callback function, or set a conditional (e.g., return log), else
+         * the callback may be applied to other events of the same class (e.g., click) */
+        window.userale.removeCallbacks(["map"]);
+    } else {
+        return false
     }
 });
 
diff --git a/src/main.js b/src/main.js
index f9b9fee..6d09c71 100644
--- a/src/main.js
+++ b/src/main.js
@@ -34,6 +34,7 @@ export let started = false;
 export {defineCustomDetails as details} from './attachHandlers.js';
 export {
     addCallbacks as addCallbacks,
+    removeCallbacks as removeCallbacks,
     packageLog as packageLog,
     packageCustomLog as packageCustomLog,
     getSelector as getSelector,
diff --git a/src/packageLogs.js b/src/packageLogs.js
index 7c4629a..4a3f282 100644
--- a/src/packageLogs.js
+++ b/src/packageLogs.js
@@ -173,7 +173,7 @@ export function packageCustomLog(customLog, detailFcn, userAction) {
 
     let log = Object.assign(metaData, customLog);
 
-    for (const func of cbHandlers.values()) {
+    for (const func of Object.values(cbHandlers)) {
       if (typeof func === 'function') {
         log = func(log, null);
         if(!log) {
@@ -247,7 +247,7 @@ export function packageIntervalLog(e) {
             'sessionID': config.sessionID
         };
 
-        for (const func of cbHandlers.values()) {
+        for (const func of Object.values(cbHandlers)) {
           if (typeof func === 'function') {
             intervalLog = func(intervalLog, null);
             if(!intervalLog) {