refactor: Lade alle window-basierten .js-Dateien dynamisch und umgebungsabhängig
- Alle Services (ae.js, de.js, da.js, kueData.js, Start.js, System.js, opcua.js) laden ihre Scripte abhängig von der Umgebung - Vermeidet unnötige globale Script-Ladung über loadWindowVariables.ts - Reduziert Netzwerklast und verbessert Modularität und Performance
This commit is contained in:
40
services/fetchKueData.ts
Normal file
40
services/fetchKueData.ts
Normal file
@@ -0,0 +1,40 @@
|
||||
// ✅ Service: /services/fetchKueData.ts
|
||||
|
||||
export const fetchKueData = async () => {
|
||||
if (typeof window === "undefined") return null;
|
||||
|
||||
// ✅ kueData.js nur bei Bedarf nachladen (Pfad abhängig von Umgebung)
|
||||
const scriptSrc =
|
||||
process.env.NODE_ENV === "production"
|
||||
? "/CPL?/CPL/SERVICE/kueData.js"
|
||||
: "/CPLmockData/SERVICE/kueData.js";
|
||||
|
||||
await new Promise<void>((resolve, reject) => {
|
||||
const script = document.createElement("script");
|
||||
script.src = scriptSrc;
|
||||
script.async = true;
|
||||
script.onload = () => resolve();
|
||||
script.onerror = () => reject("❌ Fehler beim Laden von kueData.js");
|
||||
document.body.appendChild(script);
|
||||
});
|
||||
|
||||
const win = window as any;
|
||||
|
||||
return {
|
||||
kueOnline: win.win_kueOnline ?? false,
|
||||
kueID: win.win_kueID ?? null,
|
||||
pstMinus96V: win.win_kuePSTmMinus96V ?? null,
|
||||
alarm1: win.win_kueAlarm1 ?? null,
|
||||
alarm2: win.win_kueAlarm2 ?? null,
|
||||
iso: win.win_kueIso ?? null,
|
||||
residence: win.win_kueResidence ?? null,
|
||||
cableBreak: win.win_kueCableBreak ?? null,
|
||||
groundFault: win.win_kueGroundFault ?? null,
|
||||
limit1: win.win_kueLimit1 ?? null,
|
||||
limit2Low: win.win_kueLimit2Low ?? null,
|
||||
delay1: win.win_kueDelay1 ?? null,
|
||||
loopInterval: win.win_kueLoopInterval ?? null,
|
||||
kueVersion: win.win_kueVersion ?? null,
|
||||
overflow: win.win_kueOverflow ?? null,
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user