diff --git a/CHANGELOG.md b/CHANGELOG.md index c317ad2a..6948d86f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +v1.7.2 +- +- Устранены проблемы, связанные с работой runSync при использовании большого количества переходов в одной транзакции. +- Изменили пример с использование компонента Popout. + v1.7.1 - - Обновили peer зависимости diff --git a/examples/vk-mini-apps-router-example/src/popouts/OffencePersikPopout.tsx b/examples/vk-mini-apps-router-example/src/popouts/OffencePersikPopout.tsx index 5044a08b..89e107ac 100644 --- a/examples/vk-mini-apps-router-example/src/popouts/OffencePersikPopout.tsx +++ b/examples/vk-mini-apps-router-example/src/popouts/OffencePersikPopout.tsx @@ -1,23 +1,45 @@ +import { useCallback, useRef } from 'react'; import { useRouteNavigator } from '@vkontakte/vk-mini-apps-router'; import { Alert } from '@vkontakte/vkui'; export function OffencePersikPopout() { const routeNavigator = useRouteNavigator(); - return setTimeout(() => routeNavigator.replace('/persik/sad/persik_modal/sad', { keepSearchParams: true }), 100), - }, - ]} - actionsLayout="horizontal" - onClose={() => routeNavigator.hidePopout()} - title="Еда персика" - description="Вы уверены, что хотите забрать у персика еду?" - />; + const closeWithAction = useRef(false); + + const handleTakeFood = useCallback(() => { + closeWithAction.current = true; + + routeNavigator.runSync([ + () => routeNavigator.hidePopout(), + () => routeNavigator.replace('/persik/sad/persik_modal/sad', { keepSearchParams: true }), + ]); + }, [routeNavigator]); + + const handleClose = useCallback(() => { + if (!closeWithAction.current) { + routeNavigator.hidePopout(); + } + + closeWithAction.current = false; + }, [closeWithAction, routeNavigator]); + + return ( + + ); } diff --git a/src/entities/NavigationTransaction.ts b/src/entities/NavigationTransaction.ts index ef136ddb..df1caf1d 100644 --- a/src/entities/NavigationTransaction.ts +++ b/src/entities/NavigationTransaction.ts @@ -27,9 +27,11 @@ export class NavigationTransaction { doNext(): void { if (!this.finished) { - this.actions[this.pointer](); - this.pointer += 1; + const action = this.actions[this.pointer]; + this.pointer++; + action(); } + // this.finished изменился при выполнении предыдущего условия - нельзя объединить в if-else. if (this.finished) { this.resolve(); diff --git a/src/services/TransactionExecutor.ts b/src/services/TransactionExecutor.ts index c334154c..ffa8a6d0 100644 --- a/src/services/TransactionExecutor.ts +++ b/src/services/TransactionExecutor.ts @@ -38,14 +38,11 @@ export class TransactionExecutor { public static async doNext(): Promise { const transactionExecutor = TransactionExecutor.getInstance(); const transactions = transactionExecutor.transactions; - // Нужно делать асинхронно, иначе будет бесконечный цикл навигация-изменение стейта-навигация... - setTimeout(() => { - if (transactions.length) { - transactions[0].doNext(); - if (transactions[0].finished) { - transactions.shift(); - } + if (transactions.length) { + transactions[0].doNext(); + if (transactions[0]?.finished) { + transactions.shift(); } - }); + } } }