diff --git a/Build/Sources/TypeScript/backend/storage/persistent.ts b/Build/Sources/TypeScript/backend/storage/persistent.ts index 2f4303de8f36f7c8b33c32c7afc3af503bf90e3a..eda0c065386c742be81a8ab71acba01bd550fac2 100644 --- a/Build/Sources/TypeScript/backend/storage/persistent.ts +++ b/Build/Sources/TypeScript/backend/storage/persistent.ts @@ -33,8 +33,7 @@ class Persistent { */ public get(key: string): any { if (this.data === null) { - const response = this.loadFromServer(); - return this.getRecursiveDataByDeepKey(response, key.split('.')); + this.data = this.loadFromServer(); } return this.getRecursiveDataByDeepKey(this.data, key.split('.')); @@ -133,9 +132,7 @@ class Persistent { request.send(); if (request.status === 200) { - const response = JSON.parse(request.responseText); - this.data = response; - return response; + return JSON.parse(request.responseText); } throw `Unexpected response code ${request.status}, reason: ${request.responseText}`; diff --git a/typo3/sysext/backend/Resources/Public/JavaScript/storage/persistent.js b/typo3/sysext/backend/Resources/Public/JavaScript/storage/persistent.js index 9ccfb4085b0327041e2418e5de83f7287c07b948..9fbccb7ea41eca26554d839c9c0a2bb477247356 100644 --- a/typo3/sysext/backend/Resources/Public/JavaScript/storage/persistent.js +++ b/typo3/sysext/backend/Resources/Public/JavaScript/storage/persistent.js @@ -10,4 +10,4 @@ * * The TYPO3 project - inspiring people to share! */ -import AjaxRequest from"@typo3/core/ajax/ajax-request.js";class Persistent{constructor(){this.data=null}get(e){if(null===this.data){const s=this.loadFromServer();return this.getRecursiveDataByDeepKey(s,e.split("."))}return this.getRecursiveDataByDeepKey(this.data,e.split("."))}set(e,s){return null!==this.data&&(this.data=this.setRecursiveDataByDeepKey(this.data,e.split("."),s)),this.storeOnServer(e,s)}async addToList(e,s){const t=await new AjaxRequest(TYPO3.settings.ajaxUrls.usersettings_process).post({action:"addToList",key:e,value:s});return this.resolveResponse(t)}async removeFromList(e,s){const t=await new AjaxRequest(TYPO3.settings.ajaxUrls.usersettings_process).post({action:"removeFromList",key:e,value:s});return this.resolveResponse(t)}async unset(e){const s=await new AjaxRequest(TYPO3.settings.ajaxUrls.usersettings_process).post({action:"unset",key:e});return this.resolveResponse(s)}clear(){new AjaxRequest(TYPO3.settings.ajaxUrls.usersettings_process).post({action:"clear"}),this.data=null}isset(e){const s=this.get(e);return null!=s}load(e){this.data=e}loadFromServer(){const e=new URL(location.origin+TYPO3.settings.ajaxUrls.usersettings_process);e.searchParams.set("action","getAll");const s=new XMLHttpRequest;if(s.open("GET",e.toString(),!1),s.send(),200===s.status){const e=JSON.parse(s.responseText);return this.data=e,e}throw`Unexpected response code ${s.status}, reason: ${s.responseText}`}async storeOnServer(e,s){const t=await new AjaxRequest(TYPO3.settings.ajaxUrls.usersettings_process).post({action:"set",key:e,value:s});return this.resolveResponse(t)}getRecursiveDataByDeepKey(e,s){if(1===s.length)return(e||{})[s[0]];const t=s.shift();return this.getRecursiveDataByDeepKey(e[t]||{},s)}setRecursiveDataByDeepKey(e,s,t){if(1===s.length)(e=e||{})[s[0]]=t;else{const a=s.shift();e[a]=this.setRecursiveDataByDeepKey(e[a]||{},s,t)}return e}async resolveResponse(e){const s=await e.resolve();return this.data=s,s}}export default new Persistent; \ No newline at end of file +import AjaxRequest from"@typo3/core/ajax/ajax-request.js";class Persistent{constructor(){this.data=null}get(e){return null===this.data&&(this.data=this.loadFromServer()),this.getRecursiveDataByDeepKey(this.data,e.split("."))}set(e,s){return null!==this.data&&(this.data=this.setRecursiveDataByDeepKey(this.data,e.split("."),s)),this.storeOnServer(e,s)}async addToList(e,s){const t=await new AjaxRequest(TYPO3.settings.ajaxUrls.usersettings_process).post({action:"addToList",key:e,value:s});return this.resolveResponse(t)}async removeFromList(e,s){const t=await new AjaxRequest(TYPO3.settings.ajaxUrls.usersettings_process).post({action:"removeFromList",key:e,value:s});return this.resolveResponse(t)}async unset(e){const s=await new AjaxRequest(TYPO3.settings.ajaxUrls.usersettings_process).post({action:"unset",key:e});return this.resolveResponse(s)}clear(){new AjaxRequest(TYPO3.settings.ajaxUrls.usersettings_process).post({action:"clear"}),this.data=null}isset(e){const s=this.get(e);return null!=s}load(e){this.data=e}loadFromServer(){const e=new URL(location.origin+TYPO3.settings.ajaxUrls.usersettings_process);e.searchParams.set("action","getAll");const s=new XMLHttpRequest;if(s.open("GET",e.toString(),!1),s.send(),200===s.status)return JSON.parse(s.responseText);throw`Unexpected response code ${s.status}, reason: ${s.responseText}`}async storeOnServer(e,s){const t=await new AjaxRequest(TYPO3.settings.ajaxUrls.usersettings_process).post({action:"set",key:e,value:s});return this.resolveResponse(t)}getRecursiveDataByDeepKey(e,s){if(1===s.length)return(e||{})[s[0]];const t=s.shift();return this.getRecursiveDataByDeepKey(e[t]||{},s)}setRecursiveDataByDeepKey(e,s,t){if(1===s.length)(e=e||{})[s[0]]=t;else{const a=s.shift();e[a]=this.setRecursiveDataByDeepKey(e[a]||{},s,t)}return e}async resolveResponse(e){const s=await e.resolve();return this.data=s,s}}export default new Persistent; \ No newline at end of file