2023-02-02 15:59:54 +08:00
|
|
|
<% if(appWorkerPath) {-%>import '<%- appWorkerPath %>';<% } -%>
|
2023-05-08 18:00:27 +08:00
|
|
|
<% if(!!loaders && !!dataLoader && useAppWorker) {-%>
|
2023-02-02 15:59:54 +08:00
|
|
|
import dataloaderConfig from './dataloader-config';
|
|
|
|
|
2023-05-16 17:10:01 +08:00
|
|
|
addEventListener('beforepageload', async (pageInfos = {}) => {
|
2023-02-02 15:59:54 +08:00
|
|
|
const {
|
|
|
|
key,
|
|
|
|
} = pageInfos.detail || {};
|
|
|
|
const config = dataloaderConfig[key];
|
|
|
|
if (config) {
|
|
|
|
if (typeof config === 'function') {
|
2023-05-16 17:10:01 +08:00
|
|
|
const res = await config();
|
|
|
|
pha.postMessage(res, '0');
|
2023-02-02 15:59:54 +08:00
|
|
|
} else if (Array.isArray(config)) {
|
2023-05-16 17:10:01 +08:00
|
|
|
config.forEach(async (item, index) => {
|
2023-02-02 15:59:54 +08:00
|
|
|
if (typeof item === 'function') {
|
2023-05-16 17:10:01 +08:00
|
|
|
const res = await item();
|
|
|
|
pha.postMessage(res, `$index}`);
|
2023-02-02 15:59:54 +08:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
<% } -%>
|