fragment: fix wait time

Signed-off-by: Varun Patil <radialapps@gmail.com>
pull/888/head
Varun Patil 2023-10-24 12:48:56 -07:00
parent c6358ff644
commit cf3b782cec
1 changed files with 13 additions and 2 deletions

View File

@ -127,6 +127,9 @@ export const fragment = {
query: _m.route.query, query: _m.route.query,
hash: encodeFragment(list), hash: encodeFragment(list),
}); });
// wait for the route to change
await new Promise((resolve) => setTimeout(resolve, 0));
}, },
/** /**
@ -151,6 +154,9 @@ export const fragment = {
hash: encodeFragment(this.list.slice(0, -sfrag.index! - 1)), hash: encodeFragment(this.list.slice(0, -sfrag.index! - 1)),
}); });
} }
// wait for the route to change
await new Promise((resolve) => setTimeout(resolve, 0));
}, },
/** /**
@ -163,13 +169,18 @@ export const fragment = {
/** /**
* Wrap a promise as a route fragment. * Wrap a promise as a route fragment.
* Pushes a fragment before running the promise and
* pops it *before* the promise resolves.
*/ */
async wrap<T>(promise: Promise<T>, type: FragmentType, ...args: string[]): Promise<T> { async wrap<T>(promise: Promise<T>, type: FragmentType, ...args: string[]): Promise<T> {
await this.push(type, ...args); await this.push(type, ...args);
try { try {
return await promise; const res = await promise;
} finally {
await this.pop(type); await this.pop(type);
return res;
} catch (e) {
await this.pop(type);
throw e;
} }
}, },