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(http): add has() method to HttpContext class #43887

Closed
wants to merge 1 commit into from

Conversation

HyperLife1119
Copy link
Contributor

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 current behavior?

Unable to determine whether a certain token exists in HttpContext.

What is the new behavior?

Use the has() method provided by HttpContext to detect whether a certain token exists

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

@google-cla google-cla bot added the cla: yes label Oct 19, 2021
@pullapprove pullapprove bot requested a review from IgorMinar October 19, 2021 02:52
@petebacondarwin petebacondarwin added action: cleanup The PR is in need of cleanup, either due to needing a rebase or in response to comments from reviews action: review The PR is still awaiting reviews from at least one requested reviewer area: common/http target: minor This PR is targeted for the next minor release labels Oct 19, 2021
@ngbot ngbot bot modified the milestone: Backlog Oct 19, 2021
@petebacondarwin
Copy link
Member

@HyperLife1119 - thanks for this PR.
Please can you rebase on the current angular/angular master to get the CI to run.
Also, please just squash all three commits together into a single one.
Finally, we might need to update the size tracking files if this new feature pushes the size of applications that use HttpContext over the current limit.

@HyperLife1119
Copy link
Contributor Author

@HyperLife1119 - thanks for this PR. Please can you rebase on the current angular/angular master to get the CI to run. Also, please just squash all three commits together into a single one. Finally, we might need to update the size tracking files if this new feature pushes the size of applications that use HttpContext over the current limit.

I think it should be ok. 😄

@petebacondarwin
Copy link
Member

Great! As expected we now have a couple more steps due to the new public API.

Please run yarn bazel run //packages/common:common_api.accept.

And then save it as a fixup commit (e.g. git commit -a --fixup=HEAD).

@HyperLife1119
Copy link
Contributor Author

HyperLife1119 commented Oct 20, 2021

Great! As expected we now have a couple more steps due to the new public API.

Please run yarn bazel run //packages/common:common_api.accept.

And then save it as a fixup commit (e.g. git commit -a --fixup=HEAD).

I finished.

@petebacondarwin
Copy link
Member

One more rebase please @HyperLife1119 - then I think we are good on this.

@petebacondarwin
Copy link
Member

You seem to have automatically closed the PR by pushing zero commits? Did you accidentally reset the branch to master rather than rebasing?

@HyperLife1119
Copy link
Contributor Author

Wait a minute, i'm recovering...

@petebacondarwin
Copy link
Member

I think this is the commit you need 8ba2a36

@HyperLife1119 HyperLife1119 reopened this Oct 20, 2021
@HyperLife1119
Copy link
Contributor Author

It should be ok now. @petebacondarwin

expect(context.get(IS_ENABLED)).toBe(false);
expect([...context.keys()]).toEqual([
IS_ENABLED
]); // value from factory function is stored in the map upon access

context.set(IS_ENABLED, true);
expect(context.has(IS_ENABLED)).toBe(true);
Copy link
Member

Choose a reason for hiding this comment

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

So I actually hoped for this line to be above the line that sets the value to true. I think it is a stronger test of .has() if the stored value is falsy.

@HyperLife1119
Copy link
Contributor Author

All right. @petebacondarwin

At present, the get() method provided by HttpContext will never return null. Sometimes we need to check whether an http token is included, so add the has() method to HttpContext.
@petebacondarwin petebacondarwin 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 Oct 20, 2021
Copy link
Member

@petebacondarwin petebacondarwin left a comment

Choose a reason for hiding this comment

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

Looks good to me. Thanks.

Copy link
Member

@petebacondarwin petebacondarwin 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

@HyperLife1119
Copy link
Contributor Author

This is my first PR to angular, thank you for your guidance. @petebacondarwin

Copy link
Contributor

@AndrewKushnir AndrewKushnir left a comment

Choose a reason for hiding this comment

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

@HyperLife1119 thanks for contributing to Angular! 👍

I just wanted to mention that this change adds some non-tree-shakable code to app bundles in case HTTP package is used. However the added code would be small and the new API looks reasonable (and somewhat missing in the current implementation), so we can probably justify that minimal size increase.

Reviewed-for: public-api

Copy link
Contributor

@jessicajaniuk jessicajaniuk left a comment

Choose a reason for hiding this comment

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

LGTM 🍪
Thanks for your contribution!

reviewed-for: public-api

@jessicajaniuk jessicajaniuk added action: presubmit The PR is in need of a google3 presubmit action: merge The PR is ready for merge by the caretaker and removed action: review The PR is still awaiting reviews from at least one requested reviewer action: presubmit The PR is in need of a google3 presubmit labels Nov 1, 2021
@atscott
Copy link
Contributor

atscott commented Nov 4, 2021

This PR was merged into the repository by commit d452b38.

@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Dec 5, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
action: merge The PR is ready for merge by the caretaker area: common/http cla: yes 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