Fix race when replacing views during fade
This commit is contained in:
parent
7ee735c2db
commit
371ed5a2b0
1 changed files with 9 additions and 5 deletions
14
script.js
14
script.js
|
@ -69,14 +69,18 @@
|
|||
|
||||
async function replace(view) {
|
||||
const el = ensureViewEl(view);
|
||||
if (currentBase) {
|
||||
await fadeOut(currentBase.el);
|
||||
$uxRoot.removeChild(currentBase.el);
|
||||
if (typeof currentBase.view.destroy === 'function') currentBase.view.destroy();
|
||||
const prev = currentBase;
|
||||
if (prev) {
|
||||
const prevEl = prev.el;
|
||||
if (prevEl && prevEl.isConnected) {
|
||||
await fadeOut(prevEl);
|
||||
if (prevEl.parentNode === $uxRoot) $uxRoot.removeChild(prevEl);
|
||||
}
|
||||
if (prev.view && typeof prev.view.destroy === 'function') prev.view.destroy();
|
||||
}
|
||||
$uxRoot.appendChild(el);
|
||||
await fadeIn(el);
|
||||
currentBase = { view, el };
|
||||
await fadeIn(el);
|
||||
if (typeof view.onShow === 'function') view.onShow();
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue