Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitfdf7236

Browse files
committed
feat(hmr): improved modal HMR
1 parent0e7406d commitfdf7236

File tree

1 file changed

+39
-12
lines changed

1 file changed

+39
-12
lines changed

‎src/plugins/modals.ts‎

Lines changed: 39 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {
77
unref,
88
warn,
99
}from'@vue/runtime-core';
10-
import{NSVElement}from'../dom';
10+
import{NSVElement,NSVRoot}from'../dom';
1111
import{createNativeView}from'../runtimeHelpers';
1212
import{isObject}from'@vue/shared';
1313

@@ -74,29 +74,56 @@ export async function $showModal<T = any>(
7474

7575
returnnewPromise((resolve)=>{
7676
letisResolved=false;
77-
letview=createNativeView(component,options.props);
77+
letisReloading=false;
78+
letroot=newNSVRoot();
79+
80+
constreloadModal=()=>{
81+
isReloading=true;
82+
closeModal();
83+
// reopening is done in `closeCallback`
84+
};
85+
86+
letview=createNativeView(component,options.props,{
87+
reload:reloadModal,
88+
});
7889

79-
constcloseModal=(...args:any[])=>modalContent.closeModal(...args);
8090
constcloseCallback=(data?:T)=>{
8191
if(isResolved)return;
92+
93+
if(isReloading){
94+
view.unmount();
95+
view.mount(root);
96+
openModal({
97+
// todo: for this to work nicely, we'd need to add `animated: false` to `closeModal` as well
98+
// but not currently possible without a core change.
99+
// animated: false,
100+
});
101+
isReloading=false;
102+
103+
return;
104+
}
105+
82106
isResolved=true;
83107
view.unmount();
84108
view=null;
85109

86110
resolve(data);
87111
};
88112

113+
constopenModal=(additionalOptions?:Partial<ShowModalOptions>)=>{
114+
modalTarget.showModal(view.nativeView,{
115+
...options,
116+
context:null,
117+
closeCallback,
118+
...additionalOptions,
119+
});
120+
};
121+
constcloseModal=(...args:any[])=>view.nativeView?.closeModal(...args);
122+
89123
view.context.config.globalProperties.$closeModal=closeModal;
90124
view.context.config.globalProperties.$modal={close:closeModal};
91125

92-
view.mount();
93-
94-
constmodalContent=view.nativeView;
95-
96-
modalTarget.showModal(modalContent,{
97-
...options,
98-
context:null,
99-
closeCallback,
100-
});
126+
view.mount(root);
127+
openModal();
101128
});
102129
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp