Skip to content

Commit

Permalink
onNodeActivation async (#3457)
Browse files Browse the repository at this point in the history
  • Loading branch information
hardl authored Oct 9, 2023
1 parent 25e36cb commit 43c5422
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
6 changes: 5 additions & 1 deletion core/src/navigation/services/navigation.js
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,11 @@ class NavigationClass {
}

async shouldPreventNavigation(node) {
if (node && GenericHelpers.isFunction(node.onNodeActivation) && (await node.onNodeActivation(node)) === false) {
if (
node &&
(GenericHelpers.isFunction(node.onNodeActivation) || GenericHelpers.isAsyncFunction(node.onNodeActivation)) &&
(await node.onNodeActivation(node)) === false
) {
return true;
}
return false;
Expand Down
9 changes: 9 additions & 0 deletions core/src/utilities/helpers/generic-helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,15 @@ class GenericHelpersClass {
return functionToCheck && {}.toString.call(functionToCheck) === '[object Function]';
}

/**
* Checks if input is an async function.
* @param functionToCheck mixed
* @returns {boolean}
*/
isAsyncFunction(functionToCheck) {
return functionToCheck && {}.toString.call(functionToCheck) === '[object AsyncFunction]';
}

/**
* Checks if input is a promise.
* @param promiseToCheck mixed
Expand Down

0 comments on commit 43c5422

Please sign in to comment.