Skip to content
Snippets Groups Projects
Unverified Commit 9d5702d3 authored by Bekerle, Patrizio's avatar Bekerle, Patrizio :fire:
Browse files

Migrate to "static" class variables

parent d367ef03
No related branches found
No related tags found
No related merge requests found
Pipeline #16735 passed
...@@ -4,11 +4,6 @@ import {send as notify} from './notification'; ...@@ -4,11 +4,6 @@ import {send as notify} from './notification';
import * as utils from "./utils"; import * as utils from "./utils";
import {i18n} from "./i18n"; import {i18n} from "./i18n";
let instances = {};
let successFunctions = {};
let failureFunctions = {};
let initStarted = {};
// "module.exports = class JSONLD" doesn't work with rollup because of above "import" // "module.exports = class JSONLD" doesn't work with rollup because of above "import"
export default class JSONLD { export default class JSONLD {
constructor(baseApiUrl, entities) { constructor(baseApiUrl, entities) {
...@@ -30,19 +25,19 @@ export default class JSONLD { ...@@ -30,19 +25,19 @@ export default class JSONLD {
} }
// if init api call was already successfully finished execute the success function // if init api call was already successfully finished execute the success function
if (instances[apiUrl] !== undefined) { if (JSONLD.instances[apiUrl] !== undefined) {
if (typeof successFnc == 'function') successFnc(instances[apiUrl]); if (typeof successFnc == 'function') successFnc(JSONLD.instances[apiUrl]);
return; return;
} }
// init the arrays // init the arrays
if (successFunctions[apiUrl] === undefined) successFunctions[apiUrl] = []; if (JSONLD.successFunctions[apiUrl] === undefined) JSONLD.successFunctions[apiUrl] = [];
if (failureFunctions[apiUrl] === undefined) failureFunctions[apiUrl] = []; if (JSONLD.failureFunctions[apiUrl] === undefined) JSONLD.failureFunctions[apiUrl] = [];
// add success and failure functions // add success and failure functions
if (typeof successFnc == 'function') successFunctions[apiUrl].push(successFnc); if (typeof successFnc == 'function') JSONLD.successFunctions[apiUrl].push(successFnc);
if (typeof failureFnc == 'function') failureFunctions[apiUrl].push(failureFnc); if (typeof failureFnc == 'function') JSONLD.failureFunctions[apiUrl].push(failureFnc);
} }
/** /**
...@@ -55,11 +50,11 @@ export default class JSONLD { ...@@ -55,11 +50,11 @@ export default class JSONLD {
// console.log("doInitializationOnce", apiUrl, token); // console.log("doInitializationOnce", apiUrl, token);
// check if token is not set or api call was already started // check if token is not set or api call was already started
if (!apiUrl || !token || initStarted[apiUrl] !== undefined) { if (!apiUrl || !token || JSONLD.initStarted[apiUrl] !== undefined) {
return; return;
} }
initStarted[apiUrl] = true; JSONLD.initStarted[apiUrl] = true;
JSONLD.doInitialization(apiUrl, token); JSONLD.doInitialization(apiUrl, token);
// console.log("doInitializationOnce Done", apiUrl, token); // console.log("doInitializationOnce Done", apiUrl, token);
} }
...@@ -145,11 +140,11 @@ export default class JSONLD { ...@@ -145,11 +140,11 @@ export default class JSONLD {
}); });
const instance = new JSONLD(baseUrl, entities); const instance = new JSONLD(baseUrl, entities);
instances[apiUrl] = instance; JSONLD.instances[apiUrl] = instance;
// return the initialized JSONLD object // return the initialized JSONLD object
for (const fnc of successFunctions[apiUrl]) if (typeof fnc == 'function') fnc(instance); for (const fnc of JSONLD.successFunctions[apiUrl]) if (typeof fnc == 'function') fnc(instance);
successFunctions[apiUrl] = []; JSONLD.successFunctions[apiUrl] = [];
} }
/** /**
...@@ -159,8 +154,8 @@ export default class JSONLD { ...@@ -159,8 +154,8 @@ export default class JSONLD {
* @param message * @param message
*/ */
static executeFailureFunctions(apiUrl, message = "") { static executeFailureFunctions(apiUrl, message = "") {
for (const fnc of failureFunctions[apiUrl]) if (typeof fnc == 'function') fnc(); for (const fnc of JSONLD.failureFunctions[apiUrl]) if (typeof fnc == 'function') fnc();
failureFunctions[apiUrl] = []; JSONLD.failureFunctions[apiUrl] = [];
if (message !== "") { if (message !== "") {
notify({ notify({
...@@ -172,7 +167,7 @@ export default class JSONLD { ...@@ -172,7 +167,7 @@ export default class JSONLD {
} }
static getInstance(apiUrl) { static getInstance(apiUrl) {
return instances[apiUrl]; return JSONLD.instances[apiUrl];
} }
getEntityForIdentifier(identifier) { getEntityForIdentifier(identifier) {
...@@ -283,3 +278,8 @@ export default class JSONLD { ...@@ -283,3 +278,8 @@ export default class JSONLD {
return results; return results;
} }
} }
JSONLD.instances = {};
JSONLD.successFunctions = {};
JSONLD.failureFunctions = {};
JSONLD.initStarted = {};
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment