pawajs 1.5.4 → 1.5.6
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 +42 -30
- package/package.json +1 -1
- package/pawaElement.js +4 -3
- package/reactive.js +2 -2
package/index.js
CHANGED
|
@@ -265,6 +265,9 @@ export const RegisterComponent = (...args) => {
|
|
|
265
265
|
const component = args[i + 1];
|
|
266
266
|
if (typeof name === 'string' && typeof component === 'function') {
|
|
267
267
|
// if (components.has(name.toUpperCase())) continue;
|
|
268
|
+
if (!isServer() && lazyComponents.has(name.toUpperCase())) {
|
|
269
|
+
lazyComponents.delete(name.toLocaleUpperCase())
|
|
270
|
+
}
|
|
268
271
|
components.set(name.toUpperCase(), component);
|
|
269
272
|
} else {
|
|
270
273
|
console.warn('Mismatched arguments for RegisterComponent. Expected pairs of (string, function).');
|
|
@@ -283,40 +286,49 @@ export const RegisterComponent = (...args) => {
|
|
|
283
286
|
}
|
|
284
287
|
});
|
|
285
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
|
+
|
|
286
326
|
export const createIntersectionObserver = (element, observeBy) => {
|
|
287
327
|
const observer = new IntersectionObserver(entries => {
|
|
288
328
|
entries.forEach(entry => {
|
|
289
329
|
if (entry.isIntersecting) {
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
if (!lazyData) return;
|
|
294
|
-
|
|
295
|
-
lazyData.component().then(res => {
|
|
296
|
-
const compoFunc = res[lazyData.name];
|
|
297
|
-
if (!compoFunc) return;
|
|
298
|
-
|
|
299
|
-
components.set(tagName, compoFunc);
|
|
300
|
-
lazyComponents.delete(tagName);
|
|
301
|
-
|
|
302
|
-
const instances = lazyComponentElement.get(tagName) || [];
|
|
303
|
-
while (instances.length > 0) {
|
|
304
|
-
const { element: el, func } = instances.shift();
|
|
305
|
-
if (el) {
|
|
306
|
-
if (el._component){
|
|
307
|
-
el._component.component = compoFunc;
|
|
308
|
-
el._component.validPropRule=compoFunc?.validateProps || {}
|
|
309
|
-
}
|
|
310
|
-
|
|
311
|
-
keepContext(el._stateContext);
|
|
312
|
-
el._stateContext._hasRun = false;
|
|
313
|
-
func();
|
|
314
|
-
el._stateContext._hasRun = true;
|
|
315
|
-
}
|
|
316
|
-
}
|
|
317
|
-
lazyComponentElement.delete(tagName)
|
|
318
|
-
observer.disconnect();
|
|
319
|
-
}).catch(err => console.error(`Lazy load failed for ${tagName}:`, err));
|
|
330
|
+
triggerLazyLoad(splitAndAdd(element.tagName));
|
|
331
|
+
observer.disconnect();
|
|
320
332
|
}
|
|
321
333
|
});
|
|
322
334
|
}, { rootMargin: '100px' });
|
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
|
|
|
@@ -51,10 +51,11 @@ export class PawaElement {
|
|
|
51
51
|
return Array.from(this._el.children)
|
|
52
52
|
}
|
|
53
53
|
checkLazy(){
|
|
54
|
-
if (lazyComponents.has(splitAndAdd(this._el.tagName))
|
|
54
|
+
if (lazyComponents.has(splitAndAdd(this._el.tagName))) {
|
|
55
|
+
if(components.has(splitAndAdd(this._el.tagName))) return
|
|
55
56
|
this._lazy=true
|
|
56
57
|
if (!lazyComponentElement.has(splitAndAdd(this._el.tagName))) {
|
|
57
|
-
|
|
58
|
+
triggerLazyLoad(splitAndAdd(this._el.tagName))
|
|
58
59
|
}
|
|
59
60
|
}
|
|
60
61
|
}
|
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) {
|