Skip to content

Commit

Permalink
refact HMR accept code
Browse files Browse the repository at this point in the history
  • Loading branch information
KermanX committed Jan 19, 2024
1 parent e8769f4 commit 3c00eee
Showing 1 changed file with 9 additions and 15 deletions.
24 changes: 9 additions & 15 deletions packages/hmr/src/wrapMain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,14 @@ export function ${initFuncId}(app, locals) {
${localsObjId} = locals;
}
if (import.meta.hot) {
import.meta.hot.accept((newMainModule) => {
newMainModule.${initFuncId}(${appInstDeafultId}, ${localsObjId});
const newMain = newMainModule.${mainFuncId}(${localsObjId});
if(${appInstDeafultId}.state !== "idle") {
${appInstDeafultId}.promises.mainExecuted.then(() => {
${appInstDeafultId}.main = newMain;
${appInstDeafultId}.update();
})
} else {
${appInstDeafultId}.main = newMain;
${appInstDeafultId}.update();
}
});
}
import.meta.hot?.accept(async (newMainModule) => {
newMainModule.${initFuncId}(${appInstDeafultId}, ${localsObjId});
const newMain = newMainModule.${mainFuncId}(${localsObjId});
if(${appInstDeafultId}.state !== "idle") {
await ${appInstDeafultId}.promises.mainExecuted;
}
${appInstDeafultId}.main = newMain;
${appInstDeafultId}.update();
});
`);
}

0 comments on commit 3c00eee

Please sign in to comment.