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

fix(core): support InjectFlags argument in NodeInjector.get() #41592

Closed
wants to merge 1 commit into from

Conversation

vthinkxie
Copy link
Contributor

@vthinkxie vthinkxie commented Apr 13, 2021

close #31776

the InectFlags was defined in both getOrCreateInjectable and Injector, but was ignored in NodeInjector
this PR support getting parent token via injector.get in NodeInjector

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?

Issue Number: N/A

What is the new behavior?

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

@pullapprove pullapprove bot requested a review from alxhub April 13, 2021 02:15
@google-cla google-cla bot added the cla: yes label Apr 13, 2021
@zarend zarend added the area: core Issues related to the framework runtime label Apr 13, 2021
@ngbot ngbot bot added this to the Backlog milestone Apr 13, 2021
@AndrewKushnir AndrewKushnir self-requested a review April 13, 2021 04:47
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.

@vthinkxie thanks for creating this PR. A couple comments:

  • This change should also contain a number of tests that would make sure the flags work as expected and are aligned with token injection performed via constructor arguments.
  • The NodeInjector is a part of the Ivy logic and the ViewEngine version of it doesn't seem to have the flags support either (see here). We'd need to consider adding the logic there too (for general feature parity).

We'll discuss this with the team more and I will followup here with some additional information.

Thank you.

@AndrewKushnir AndrewKushnir removed the request for review from alxhub April 13, 2021 20:26
@AndrewKushnir AndrewKushnir added action: review The PR is still awaiting reviews from at least one requested reviewer feature Issue that requests a new feature target: minor This PR is targeted for the next minor release core: di labels Apr 13, 2021
@AndrewKushnir AndrewKushnir self-assigned this Apr 13, 2021
@AndrewKushnir
Copy link
Contributor

Hi @vthinkxie, sorry for the delay in answering.

We've discussed this feature request with the team and we'd like to move forward with the implementation. A couple notes:

  • Passing flags from NodeInjector.get -> getOrCreateInjectable makes sense.
  • This change requires a number of tests that would make sure the flags work as expected and are aligned with token injection performed via constructor arguments. You can add more tests in the packages/core/test/acceptance/di_spec.ts file.
  • Since ViewEngine is deprecated, the change can be isolated to Ivy code only (i.e. what you've already changed).

Please let me know if any additional information is required (on adding tests or anything else related to this change).

Thank you.

@vthinkxie vthinkxie force-pushed the node-injector-flags branch 5 times, most recently from 69448a4 to cbb39e5 Compare April 29, 2021 06:48
@vthinkxie
Copy link
Contributor Author

Hi @AndrewKushnir

I have added some tests in packages/core/test/acceptance/di_spec.ts, could you have a look? thanks

packages/core/src/di/injector.ts Outdated Show resolved Hide resolved
packages/core/test/acceptance/di_spec.ts Outdated Show resolved Hide resolved
packages/core/test/acceptance/di_spec.ts Outdated Show resolved Hide resolved
packages/core/test/acceptance/di_spec.ts Outdated Show resolved Hide resolved
packages/core/test/acceptance/di_spec.ts Outdated Show resolved Hide resolved
packages/core/test/acceptance/di_spec.ts Outdated Show resolved Hide resolved
packages/core/test/acceptance/di_spec.ts Outdated Show resolved Hide resolved
packages/core/test/acceptance/di_spec.ts Outdated Show resolved Hide resolved
@vthinkxie vthinkxie force-pushed the node-injector-flags branch 4 times, most recently from 425d945 to 0abe20f Compare May 8, 2021 02:05
@vthinkxie
Copy link
Contributor Author

Hi @AndrewKushnir
thanks for your review, I have updated the code, could you take a look?

@AndrewKushnir
Copy link
Contributor

Hi @vthinkxie, thanks for addressing the feedback. I will have a look at the changes within the next couple days and let you know.

One thing that I noticed is that the ci/circleci: components-repo-unit-tests CI job is failing. I've looked at the failure and found the code in Components repo that relies on the Injector.get flags, see here. My guess is that the mentioned code assumes that the 3rd argument is supported (when it's actually ignored) and the change that you made in this PR makes use of that argument, thus changing the result. We will look into this more and let you know.

Thank you.

@vthinkxie
Copy link
Contributor Author

vthinkxie commented May 11, 2021

Thanks, @AndrewKushnir
hope this PR will be in time for the v12 release

@petebacondarwin
Copy link
Member

Oh there is a typo in the commit message. Can we update it to:

fix(core): support `InjectFlags` argument in `NodeInjector.get()`

The `InjectFlags` argument was defined for both `getOrCreateInjectable()` and `Injector`, but was ignored in `NodeInjector`.
This PR adds support for getting parent token via `NodeInjector.get()`.

Closes #31776

The `InjectFlags` argument was defined for both `getOrCreateInjectable()` and `Injector`, but was ignored in `NodeInjector`.
This PR adds support for getting parent token via `NodeInjector.get()`.

close angular#31776
@vthinkxie vthinkxie changed the title fix(core): support flags option in NodeInjector.get fix(core): support InjectFlags argument in NodeInjector.get() Oct 22, 2021
@vthinkxie
Copy link
Contributor Author

Oh there is a typo in the commit message. Can we update it to:

fix(core): support `InjectFlags` argument in `NodeInjector.get()`

The `InjectFlags` argument was defined for both `getOrCreateInjectable()` and `Injector`, but was ignored in `NodeInjector`.
This PR adds support for getting parent token via `NodeInjector.get()`.

Closes #31776

done

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.

@vthinkxie thanks for working on this change 👍

@AndrewKushnir
Copy link
Contributor

Presubmit.

@AndrewKushnir
Copy link
Contributor

Quick update after running tests in Google's codebase: there is a failing target with the changes from this PR. The underlying reason is that the 3rd argument was provided (the flags), but the code used to ignore it and with this change, the correct logic is now invoked. The situation is similar to the one we have in the Components repo (where the injector.get is used with flags, assuming NodeInjector there). The code in Google's codebase can be cleaned up, but I wanted to ask if Components team can help with the assessment of whether the mentioned code in the Components repo may become an issue (may start failing in some situations after we merge this change) and if we should preemptively remove the InjectFlags.Self (since it should have no effect right now).

// cc @crisbeto @jelbourn

@AndrewKushnir AndrewKushnir added state: blocked and removed action: presubmit The PR is in need of a google3 presubmit action: review The PR is still awaiting reviews from at least one requested reviewer labels Oct 26, 2021
@crisbeto
Copy link
Member

The linked code from the Components repo should still work. We added the | InjectFlags.Optional specifically to unblock this PR.

@petebacondarwin
Copy link
Member

@crisbeto:

Tthe concern was more that InjectFlags.Self was not being passed through before, and now will be. So previously it would have had no effect and now it will. If this makes no difference then is there a reason to have that flag there at all?

Also, I don't understand why this code would fail after this PR but not before? Does passing undefined equate to passing InjectFlags.Optional?

@crisbeto
Copy link
Member

I think that we want to keep the InjectFlags.Self there, because we only want the control from the date range input itself. I suspect that this worked fine before, because there was always a control on the same level so the injector didn't have to look up the NgControl in a parent.

Regarding the optional flag, my understanding was that if it isn't passed, the injector will throw an error if it can't find the token, whereas with the flag it returns the fallback value.

@AndrewKushnir
Copy link
Contributor

@crisbeto thanks for the comment. I will proceed with the cleanup in Google's codebase and provide an update once we can proceed with the merge (hopefully within the next couple days).

@AndrewKushnir
Copy link
Contributor

Global Presubmit #2 (internal-only link).

@AndrewKushnir AndrewKushnir added action: presubmit The PR is in need of a google3 presubmit and removed state: blocked action: presubmit The PR is in need of a google3 presubmit labels Oct 28, 2021
@AndrewKushnir
Copy link
Contributor

FYI presubmits went well. @petebacondarwin please let us know if you have any additional feedback and if not, we can proceed with the merge. Thank you.

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.

Let's merge it!

@petebacondarwin petebacondarwin added the action: merge The PR is ready for merge by the caretaker label Oct 28, 2021
@alxhub
Copy link
Member

alxhub commented Oct 28, 2021

This PR was merged into the repository by commit 65cb2c5.

alxhub pushed a commit that referenced this pull request Oct 28, 2021
…1592)

The `InjectFlags` argument was defined for both `getOrCreateInjectable()` and `Injector`, but was ignored in `NodeInjector`.
This PR adds support for getting parent token via `NodeInjector.get()`.

close #31776

PR Close #41592
alxhub pushed a commit that referenced this pull request Oct 28, 2021
…1592)

The `InjectFlags` argument was defined for both `getOrCreateInjectable()` and `Injector`, but was ignored in `NodeInjector`.
This PR adds support for getting parent token via `NodeInjector.get()`.

close #31776

PR Close #41592
@alxhub alxhub closed this in 65cb2c5 Oct 28, 2021
@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 Nov 28, 2021
Serginho pushed a commit to TuLotero/angular that referenced this pull request Jan 20, 2022
…gular#41592)

The `InjectFlags` argument was defined for both `getOrCreateInjectable()` and `Injector`, but was ignored in `NodeInjector`.
This PR adds support for getting parent token via `NodeInjector.get()`.

close angular#31776

PR Close angular#41592
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: core Issues related to the framework runtime cla: yes core: di target: patch This PR is targeted for the next patch release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

DI - Handle the "InjectFlags" in Injector_.get()
8 participants