divolte.signal isn't available when window.define.amd is defined

30 views
Skip to first unread message

Peter Ruijter

unread,
Feb 11, 2020, 2:46:14 PM2/11/20
to divolte-collector
Hi guys,

A question that breaks my head. We load Divolte (0.8.0) dynamically as part of a script that collects information about articles on a page on multiple sites. This goes without any problem but when window.define.amd is defined Divolte is loaded, a pageview is sent, but the execution of divolte.signal returns the error: 

Uncaught TypeError: divolte.signal is not a function

Defining a global variable divolte and try to assign the divolte object to the variable with require("divolte"), require("p"), define("divolte", [] divolte) or define("p", [] divolte) results in undefined divolte /p and Cannot find module errors.

In the minified script I saw divolte should be loaded into
window.divolte if window.define.amd is true, although it will not happen:

"function" === typeof g.define && g.define.amd ? g.define(function () {
   return p
 }) : "undefined" !== typeof g.module &&
 g.module.exports ? g.module.exports = p : g.divolte = p;

Wouldn't this implementation be better in the next release of divolte?
if ("object" !== typeof window['divolte']) {
   // Expose divolte module.
   if (typeof window['define'] === "function" && window['define']['amd']) {
     window['define'](function () {
       return divolte;
     });
   } else if (typeof window['module'] !== 'undefined' && window['module']['exports']) {
     window['module']['exports'] = divolte;
   } else {
     window['divolte'] = divolte;
   }
   log("Module initialized.", divolte);

I am curious and look forward to finding a solution with this version of divolte.

Kind regards,

Peter Ruijter
Reply all
Reply to author
Forward
0 new messages