Mejorado la carga de IndexElement
This commit is contained in:
@@ -8,5 +8,6 @@
|
|||||||
<body>
|
<body>
|
||||||
<h1>Si ves esto, ha ocurrido un fallo critico en la compilación de TeleSec</h1>
|
<h1>Si ves esto, ha ocurrido un fallo critico en la compilación de TeleSec</h1>
|
||||||
<p>Esto NUNCA deberia de ser mostrado.</p>
|
<p>Esto NUNCA deberia de ser mostrado.</p>
|
||||||
|
<a href="dist/index.html">Intenta recargar la página</a>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
@@ -3,30 +3,36 @@ try {
|
|||||||
} catch {
|
} catch {
|
||||||
console.log("ScreenLock Failed");
|
console.log("ScreenLock Failed");
|
||||||
}
|
}
|
||||||
const debounce = (callback, wait) => {
|
const debounce = (id, callback, wait, args) => {
|
||||||
let isLocked = false;
|
// debounce with trailing callback
|
||||||
let lastArgs = null;
|
// First call runs immediately, then locks for 'wait' ms
|
||||||
let timeoutId = null;
|
// If called during lock, saves the latest args and runs once after lock
|
||||||
|
// If not called during lock, does nothing
|
||||||
return (...args) => {
|
if (!debounce.timers) {
|
||||||
if (!isLocked) {
|
debounce.timers = {};
|
||||||
// First call: run immediately
|
debounce.args = {};
|
||||||
callback(...args);
|
}
|
||||||
isLocked = true;
|
if (!debounce.timers[id]) {
|
||||||
|
// No lock, run immediately
|
||||||
// Start lock period
|
debounce.args[id] = Array.isArray(args) ? args : [args];
|
||||||
timeoutId = setTimeout(() => {
|
// Spread syntax requires ...iterable[Symbol.iterator] to be a function
|
||||||
isLocked = false;
|
callback(...debounce.args[id]);
|
||||||
if (lastArgs) {
|
debounce.timers[id] = setTimeout(() => {
|
||||||
callback(...lastArgs);
|
if (debounce.args[id]) {
|
||||||
lastArgs = null;
|
callback(...debounce.args[id]);
|
||||||
}
|
debounce.args[id] = null;
|
||||||
}, wait);
|
debounce.timers[id] = setTimeout(() => {
|
||||||
} else {
|
debounce.timers[id] = null;
|
||||||
// During lock: save latest args
|
}, wait);
|
||||||
lastArgs = args;
|
} else {
|
||||||
}
|
debounce.timers[id] = null;
|
||||||
};
|
}
|
||||||
|
}, wait);
|
||||||
|
} else {
|
||||||
|
// Lock active, save latest args
|
||||||
|
debounce.args[id] = Array.isArray(args) ? args : [args];
|
||||||
|
}
|
||||||
|
return id;
|
||||||
};
|
};
|
||||||
|
|
||||||
const wheelcolors = [
|
const wheelcolors = [
|
||||||
@@ -708,7 +714,7 @@ function TS_IndexElement(
|
|||||||
const searchKeyEl = document.getElementById(searchKeyInput);
|
const searchKeyEl = document.getElementById(searchKeyInput);
|
||||||
searchKeyEl.addEventListener(
|
searchKeyEl.addEventListener(
|
||||||
"input",
|
"input",
|
||||||
debounce(() => render(), 300)
|
() => debounce("search", render, 300, [rows])
|
||||||
);
|
);
|
||||||
|
|
||||||
function searchInData(data, searchValue, config) {
|
function searchInData(data, searchValue, config) {
|
||||||
@@ -769,8 +775,8 @@ function TS_IndexElement(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// --- Optimized render function ---
|
// --- Optimized render function ---
|
||||||
let lastSearchValue = "";
|
var lastSearchValue = "";
|
||||||
let lastFilteredSorted = [];
|
var lastFilteredSorted = [];
|
||||||
function sorter(a, b) {
|
function sorter(a, b) {
|
||||||
if (a.Fecha && b.Fecha) {
|
if (a.Fecha && b.Fecha) {
|
||||||
if (a.Fecha < b.Fecha) return -1;
|
if (a.Fecha < b.Fecha) return -1;
|
||||||
@@ -816,7 +822,7 @@ function TS_IndexElement(
|
|||||||
return filtered;
|
return filtered;
|
||||||
}
|
}
|
||||||
|
|
||||||
function render() {
|
function render(rows) {
|
||||||
const searchValue = searchKeyEl.value.toLowerCase().trim();
|
const searchValue = searchKeyEl.value.toLowerCase().trim();
|
||||||
// Use document fragment for batch DOM update
|
// Use document fragment for batch DOM update
|
||||||
const fragment = document.createDocumentFragment();
|
const fragment = document.createDocumentFragment();
|
||||||
@@ -1012,7 +1018,7 @@ function TS_IndexElement(
|
|||||||
} else {
|
} else {
|
||||||
delete rows[key];
|
delete rows[key];
|
||||||
}
|
}
|
||||||
render();
|
debounce("loadrow", render, 300, [rows])
|
||||||
}
|
}
|
||||||
if (typeof data == "string") {
|
if (typeof data == "string") {
|
||||||
TS_decrypt(data, SECRET, (data) => {
|
TS_decrypt(data, SECRET, (data) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user