Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(router): export function to run guards serially #55890

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

junpls
Copy link

@junpls junpls commented May 20, 2024

When multiple guards are defined for a route, they run concurrently by default. There are use cases in which it is desirable to compose guards serially, e.g., when one guard depends on pre-conditions established by another one. A basic runSerially function existed in the tests already. This commit makes the function importable and modifies it to handle more edge cases that will occur in practical use.

PR Checklist

Please check if your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Documentation content changes
  • angular.io application / infrastructure changes
  • Other... Please describe:

What is the new behavior?

A helper function is added to compose functional guards serially.

Does this PR introduce a breaking change?

  • Yes
  • No

@pullapprove pullapprove bot requested a review from atscott May 20, 2024 13:22
@angular-robot angular-robot bot added the detected: feature PR contains a feature commit label May 20, 2024
Copy link
Contributor

@atscott atscott left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

* @param guards An array of functional guards that should be executed in the declared order.
* @returns The combined functional guard.
*/
export function runSerially(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In order for this to be part of the public API, you also have to export it from packages/router/src/index.ts and then run the command to accept the new public API golden: yarn bazel run //packages/router:router_api.accept

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be great to also add @publicApi, usually at the last of the JSDoc.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the quick feedback. I will use the same JSDoc footer section as in the other functions within this file.

@atscott atscott added area: router target: minor This PR is targeted for the next minor release labels May 20, 2024
@ngbot ngbot bot added this to the Backlog milestone May 20, 2024
@junpls junpls requested review from JeanMeche and atscott May 20, 2024 15:31
@junpls junpls requested a review from atscott May 20, 2024 19:31
Copy link
Member

@pkozlowski-opensource pkozlowski-opensource left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Reviewed-for: public-api

@pkozlowski-opensource pkozlowski-opensource added the action: cleanup The PR is in need of cleanup, either due to needing a rebase or in response to comments from reviews label May 28, 2024
@pkozlowski-opensource
Copy link
Member

This PR will need rebase after all the recent merges.

Copy link

github-actions bot commented May 28, 2024

Deployed adev-preview for 39f4984 to: https://ng-dev-previews-fw--pr-angular-angular-55890-adev-prev-prhspsgj.web.app

Note: As new commits are pushed to this pull request, this link is updated after the preview is rebuilt.

Copy link
Member

@JeanMeche JeanMeche left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Docs wise

When multiple guards are defined for a route, they run concurrently by default. There are use cases in which it is desirable to compose guards serially, e.g., when one guard depends on pre-conditions established by another one.
A basic `runSerially` function existed in the tests already. This commit makes the function importable and modifies it to handle more edge cases that will occur in practical use.
@atscott atscott removed the action: cleanup The PR is in need of cleanup, either due to needing a rebase or in response to comments from reviews label Jun 6, 2024
Copy link
Contributor

@atscott atscott left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reviewed-for: public-api

@pullapprove pullapprove bot requested a review from thePunderWoman June 6, 2024 20:16
Copy link
Contributor

@thePunderWoman thePunderWoman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reviewed-for: public-api

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
adev: preview area: router detected: feature PR contains a feature commit target: minor This PR is targeted for the next minor release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants