pawajs 1.5.5 → 1.5.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +40 -31
- package/package.json +1 -1
- package/pawaElement.js +3 -4
- package/reactive.js +2 -2
package/index.js
CHANGED
|
@@ -286,40 +286,49 @@ export const RegisterComponent = (...args) => {
|
|
|
286
286
|
}
|
|
287
287
|
});
|
|
288
288
|
}
|
|
289
|
+
/**
|
|
290
|
+
* Shared helper to trigger the dynamic import and hydration of a lazy component.
|
|
291
|
+
* @param {string} tagName
|
|
292
|
+
*/
|
|
293
|
+
export const triggerLazyLoad = (tagName) => {
|
|
294
|
+
const lazyData = lazyComponents.get(tagName);
|
|
295
|
+
if (!lazyData) return;
|
|
296
|
+
|
|
297
|
+
lazyData.component().then(res => {
|
|
298
|
+
const compoFunc = res[lazyData.name];
|
|
299
|
+
if (!compoFunc) return;
|
|
300
|
+
|
|
301
|
+
components.set(tagName, compoFunc);
|
|
302
|
+
lazyComponents.delete(tagName);
|
|
303
|
+
|
|
304
|
+
const instances = lazyComponentElement.get(tagName) || [];
|
|
305
|
+
while (instances.length > 0) {
|
|
306
|
+
const { element: el, func } = instances.shift();
|
|
307
|
+
if (el) {
|
|
308
|
+
queueMicrotask(() => {
|
|
309
|
+
el.style.opacity = "";
|
|
310
|
+
if (el._component) {
|
|
311
|
+
el._component.component = compoFunc;
|
|
312
|
+
el._component.validPropRule = compoFunc?.validateProps || {}
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
keepContext(el._stateContext);
|
|
316
|
+
el._stateContext._hasRun = false;
|
|
317
|
+
func();
|
|
318
|
+
el._stateContext._hasRun = true;
|
|
319
|
+
});
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
lazyComponentElement.delete(tagName);
|
|
323
|
+
}).catch(err => console.error(`Lazy load failed for ${tagName}:`, err));
|
|
324
|
+
};
|
|
325
|
+
|
|
289
326
|
export const createIntersectionObserver = (element, observeBy) => {
|
|
290
327
|
const observer = new IntersectionObserver(entries => {
|
|
291
328
|
entries.forEach(entry => {
|
|
292
329
|
if (entry.isIntersecting) {
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
if (!lazyData) return;
|
|
297
|
-
|
|
298
|
-
lazyData.component().then(res => {
|
|
299
|
-
const compoFunc = res[lazyData.name];
|
|
300
|
-
if (!compoFunc) return;
|
|
301
|
-
|
|
302
|
-
components.set(tagName, compoFunc);
|
|
303
|
-
lazyComponents.delete(tagName);
|
|
304
|
-
|
|
305
|
-
const instances = lazyComponentElement.get(tagName) || [];
|
|
306
|
-
while (instances.length > 0) {
|
|
307
|
-
const { element: el, func } = instances.shift();
|
|
308
|
-
if (el) {
|
|
309
|
-
if (el._component){
|
|
310
|
-
el._component.component = compoFunc;
|
|
311
|
-
el._component.validPropRule=compoFunc?.validateProps || {}
|
|
312
|
-
}
|
|
313
|
-
|
|
314
|
-
keepContext(el._stateContext);
|
|
315
|
-
el._stateContext._hasRun = false;
|
|
316
|
-
func();
|
|
317
|
-
el._stateContext._hasRun = true;
|
|
318
|
-
}
|
|
319
|
-
}
|
|
320
|
-
lazyComponentElement.delete(tagName)
|
|
321
|
-
observer.disconnect();
|
|
322
|
-
}).catch(err => console.error(`Lazy load failed for ${tagName}:`, err));
|
|
330
|
+
triggerLazyLoad(splitAndAdd(element.tagName));
|
|
331
|
+
observer.disconnect();
|
|
323
332
|
}
|
|
324
333
|
});
|
|
325
334
|
}, { rootMargin: '100px' });
|
|
@@ -952,7 +961,7 @@ const component = (el, resume = false, attr, notRender, stopResume) => {
|
|
|
952
961
|
trackElement._stateContext=el._stateContext
|
|
953
962
|
addLazyComponentElement(trackElement,()=>resumer.resume_component?.(el, attr, setStateContext, mapsPlugins, formerStateContext, pawaContext, stateWatch, { comment, endComment, name, serialized, id, children }))
|
|
954
963
|
if (lazyComponentElement.has(name.toUpperCase())) {
|
|
955
|
-
|
|
964
|
+
triggerLazyLoad(trackElement.tagName)
|
|
956
965
|
}
|
|
957
966
|
}else{
|
|
958
967
|
resumer.resume_component?.(el, attr, setStateContext, mapsPlugins, formerStateContext, pawaContext, stateWatch, { comment, endComment, name, serialized, id, children })
|
package/package.json
CHANGED
package/pawaElement.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {components,lazyComponents ,escapePawaAttribute,getPawaAttributes,getDependentAttribute,getPrimaryDirectives, pluginsMap } from './index.js';
|
|
2
2
|
import {splitAndAdd,replaceTemplateOperators,setPawaDevError,getEvalValues, checkKeywordsExistence} from './utils.js';
|
|
3
3
|
import PawaComponent from './pawaComponent.js';
|
|
4
|
-
import {
|
|
4
|
+
import { triggerLazyLoad } from './index.js';
|
|
5
5
|
import { addLazyComponentElement } from './index.js';
|
|
6
6
|
import { lazyComponentElement } from './index.js';
|
|
7
7
|
|
|
@@ -54,9 +54,8 @@ export class PawaElement {
|
|
|
54
54
|
if (lazyComponents.has(splitAndAdd(this._el.tagName))) {
|
|
55
55
|
if(components.has(splitAndAdd(this._el.tagName))) return
|
|
56
56
|
this._lazy=true
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
}
|
|
57
|
+
triggerLazyLoad(splitAndAdd(this._el.tagName))
|
|
58
|
+
|
|
60
59
|
}
|
|
61
60
|
}
|
|
62
61
|
safeEval(context,expression,directive,resolve=false){
|
package/reactive.js
CHANGED
|
@@ -30,8 +30,8 @@ function scheduleRenderWithTimeBudget() {
|
|
|
30
30
|
|
|
31
31
|
rafScheduled = true;
|
|
32
32
|
scheduleInProgress=true
|
|
33
|
-
requestAnimationFrame(() => {
|
|
34
|
-
const start =
|
|
33
|
+
requestAnimationFrame((timestamp) => {
|
|
34
|
+
const start = timestamp;
|
|
35
35
|
const processed = [];
|
|
36
36
|
|
|
37
37
|
for (const fn of scheduled) {
|