From 3b0f8b7c0353778045e7fb39252c20b1de4492b0 Mon Sep 17 00:00:00 2001
From: Christoph Reiter <reiter.christoph@gmail.com>
Date: Tue, 23 Mar 2021 13:13:33 +0100
Subject: [PATCH] Deprecate JSONLD.initialize()

Use "await JSONLD.getInstance()" instead
---
 packages/auth/src/auth-keycloak.js               |  2 +-
 .../src/check-in-place-select.js                 |  2 +-
 packages/common/jsonld.js                        | 16 +++++++++++-----
 .../src/organization-select.js                   |  2 +-
 packages/person-profile/src/person-profile.js    |  2 +-
 packages/person-select/src/person-select.js      |  2 +-
 6 files changed, 16 insertions(+), 10 deletions(-)

diff --git a/packages/auth/src/auth-keycloak.js b/packages/auth/src/auth-keycloak.js
index 9c0d66d5..495bf6c6 100644
--- a/packages/auth/src/auth-keycloak.js
+++ b/packages/auth/src/auth-keycloak.js
@@ -117,7 +117,7 @@ export class AuthKeycloak extends AdapterLitElement {
         const that = this;
 
         if (newPerson && this.loadPerson) {
-            JSONLD.initialize(this.entryPointUrl, (jsonld) => {
+            JSONLD.getInstance(this.entryPointUrl).then((jsonld) => {
                 // find the correct api url for the current person
                 // we are fetching the logged-in person directly to respect the REST philosophy
                 // see: https://github.com/api-platform/api-platform/issues/337
diff --git a/packages/check-in-place-select/src/check-in-place-select.js b/packages/check-in-place-select/src/check-in-place-select.js
index f9c721d4..7b63bb9a 100644
--- a/packages/check-in-place-select/src/check-in-place-select.js
+++ b/packages/check-in-place-select/src/check-in-place-select.js
@@ -117,7 +117,7 @@ export class CheckInPlaceSelect extends ScopedElementsMixin(AdapterLitElement) {
     initJSONLD(ignorePreset = false) {
         const that = this;
 
-        JSONLD.initialize(this.entryPointUrl, function (jsonld) {
+        JSONLD.getInstance(this.entryPointUrl).then(function (jsonld) {
             that.jsonld = jsonld;
             that.active = true;
 
diff --git a/packages/common/jsonld.js b/packages/common/jsonld.js
index 2b0cb4dd..f56552b0 100644
--- a/packages/common/jsonld.js
+++ b/packages/common/jsonld.js
@@ -20,7 +20,7 @@ export default class JSONLD {
         let promise = JSONLD.promises[apiUrl];
         if (promise === undefined) {
             promise = new Promise((resolve, reject) => {
-                JSONLD.initialize(
+                JSONLD._initialize(
                     apiUrl,
                     (instance) => resolve(instance),
                     (error) => reject(error),
@@ -33,6 +33,16 @@ export default class JSONLD {
     }
 
     static initialize(apiUrl, successFnc, failureFnc, lang = 'de') {
+        console.warn('DEPRECATED: JSONLD.initialize(), use JSONLD.getInstance() instead');
+        JSONLD._initialize(apiUrl, successFnc, failureFnc, lang);
+    }
+
+    static doInitializationOnce(apiUrl) {
+        // No longer needed, remove any calls
+        console.warn('DEPRECATED: JSONLD.doInitializationOnce() calls can be removed');
+    }
+
+    static _initialize(apiUrl, successFnc, failureFnc, lang = 'de') {
         if (lang !== 'de') {
             i18n.changeLanguage(lang);
         }
@@ -60,10 +70,6 @@ export default class JSONLD {
         JSONLD._doInitialization(apiUrl);
     }
 
-    static doInitializationOnce(apiUrl) {
-        // No longer needed, remove any calls
-    }
-
     static _doInitialization(apiUrl) {
         const xhr = new XMLHttpRequest();
         xhr.open("GET", apiUrl, true);
diff --git a/packages/organization-select/src/organization-select.js b/packages/organization-select/src/organization-select.js
index 2c9967c2..ee212b9d 100644
--- a/packages/organization-select/src/organization-select.js
+++ b/packages/organization-select/src/organization-select.js
@@ -194,7 +194,7 @@ export class OrganizationSelect extends AdapterLitElement {
                     break;
                 }
                 case "entryPointUrl":
-                    JSONLD.initialize(this.entryPointUrl, (jsonld) => {
+                    JSONLD.getInstance(this.entryPointUrl).then((jsonld) => {
                         this.jsonld = jsonld;
                     }, {}, this.lang);
                     break;
diff --git a/packages/person-profile/src/person-profile.js b/packages/person-profile/src/person-profile.js
index 8a3fe9c3..c8118ba5 100644
--- a/packages/person-profile/src/person-profile.js
+++ b/packages/person-profile/src/person-profile.js
@@ -45,7 +45,7 @@ export class PersonProfile extends DBPLitElement {
                 case "entryPointUrl": {
                     const that = this;
 
-                    JSONLD.initialize(this.entryPointUrl, function (jsonld) {
+                    JSONLD.getInstance(this.entryPointUrl).then(function (jsonld) {
                         that.jsonld = jsonld;
                     }, {}, that.lang);
                     break;
diff --git a/packages/person-select/src/person-select.js b/packages/person-select/src/person-select.js
index 9c309be8..bbaf34b3 100644
--- a/packages/person-select/src/person-select.js
+++ b/packages/person-select/src/person-select.js
@@ -108,7 +108,7 @@ export class PersonSelect extends ScopedElementsMixin(AdapterLitElement) {
     initJSONLD(ignorePreset = false) {
         const that = this;
 
-        JSONLD.initialize(this.entryPointUrl, function (jsonld) {
+        JSONLD.getInstance(this.entryPointUrl).then(function (jsonld) {
             that.jsonld = jsonld;
             that.active = that.authenticated();
 
-- 
GitLab