Skip to content

feat(core): initial API work for tree shakable injectors - #20850

Closed
tinayuangao wants to merge 2 commits into
angular:masterfrom
tinayuangao:module
Closed

tinayuangao wants to merge 2 commits into
angular:masterfrom
tinayuangao:module

Conversation

@tinayuangao

Copy link
Copy Markdown
Contributor

PR Checklist

Please check if your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

[ ] Bugfix
[x ] 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?

Current Injectable don't take any parameters.

What is the new behavior?

Injectable can be used with NgModule and provider

Does this PR introduce a breaking change?

[ ] Yes
[x ] No

Other information

@googlebot

Copy link
Copy Markdown

So there's good news and bad news.

👍 The good news is that everyone that needs to sign a CLA (the pull request submitter and all commit authors) have done so. Everything is all good there.

😕 The bad news is that it appears that one or more commits were authored by someone other than the pull request submitter. We need to confirm that all authors are ok with their commits being contributed to this project. Please have them confirm that here in the pull request.

Note to project maintainer: This is a terminal state, meaning the cla/google commit status will not change from this State. It's up to you to confirm consent of the commit author(s) and merge this pull request when appropriate.

@mary-poppins

Copy link
Copy Markdown

You can preview 408eaba at https://pr20850-408eaba.ngbuilds.io/.

@jasonaden jasonaden added area: core Issues related to the framework runtime action: review The PR is still awaiting reviews from at least one requested reviewer aio: preview and removed cla: no aio: preview action: review The PR is still awaiting reviews from at least one requested reviewer labels Dec 7, 2017
@mary-poppins

Copy link
Copy Markdown

You can preview 25c7788 at https://pr20850-25c7788.ngbuilds.io/.

@tinayuangao
tinayuangao force-pushed the module branch 2 times, most recently from e772936 to b4fd66b Compare December 7, 2017 01:22
@mary-poppins

Copy link
Copy Markdown

You can preview e772936 at https://pr20850-e772936.ngbuilds.io/.

@mary-poppins

Copy link
Copy Markdown

You can preview b4fd66b at https://pr20850-b4fd66b.ngbuilds.io/.

@mary-poppins

Copy link
Copy Markdown

You can preview d6dad71 at https://pr20850-d6dad71.ngbuilds.io/.

@mary-poppins

Copy link
Copy Markdown

You can preview a59b047 at https://pr20850-a59b047.ngbuilds.io/.

@mary-poppins

Copy link
Copy Markdown

You can preview 6fd9547 at https://pr20850-6fd9547.ngbuilds.io/.

@mhevery mhevery left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Excellent work! We are a bit light on tests, but otherwise this is a very sold start.

Please address the comments, and I will have another look when ready

Comment thread packages/core/src/di/injector.ts Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

this will end up as public API, and I don't think we want to point to the design doc from there. Maybe remove the design doc link?

Comment thread packages/core/src/di/injector.ts Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

move this TS issue into a comment, so that it is not part of the Public API.

Comment thread packages/core/src/di/injector.ts Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think we need to process this in different order.
Given

@NgModule({
  provides: [{provide: Foo, useValue: 'fooChild'}]
})
class ModuleChild {}

@NgModule({
  provides: [{provide: Foo, useValue: 'fooParent'}]
  imports: [ModuleChild]
})
class ModuleParent {}

In the above case the ModuleParent's providers should override that of ModuleChild, which means that Foo should be fooParent not fooChild. The way it is being processed now the imports are being overwritten.

So I think we need to process providers first and than process providers.

Also please add a tests which demonstrates it.

Comment thread packages/core/src/di/injector.ts Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

can you add a tests which shows that providerOrInjectorDefType.ngInjectorDef.type gets instantiated eagerly? Which means that we will probably have to collect all of them into some array and than when the injector is done constructing we need to iterate over the array and retrieve all of the types so that they get treated.

Comment thread packages/core/src/di/injector.ts Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

using find is not as performant as doing a for loop over the array. Since retrieval is time sensitive could you use a for loop.

Also we should be looking up the token only if we don't have record since otherwise we are wasting time. Please move closer to the place of use.

Comment thread packages/core/src/di/injector.ts Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Also add record here so that we can cache the parent value. This will also increase performance.

Comment thread packages/core/src/metadata/ng_module.ts Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I don't think ngModule will ever be not defined. So this check is not needed.

Comment thread packages/core/src/metadata/ng_module.ts Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

What is the TODO comment for?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

  1. use Injector.create since that is the public API.
  2. Until that TS bug gets fixed we should change the public API to take Type so that we can avoid these casts.

Comment thread tools/public_api_guard/core/core.d.ts Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We need to export all of the SenProviders as well

@IgorMinar
IgorMinar self-requested a review December 8, 2017 23:09
@tinayuangao
tinayuangao force-pushed the module branch 2 times, most recently from a024bb2 to 38258e1 Compare December 11, 2017 20:23
@mary-poppins

Copy link
Copy Markdown

You can preview a024bb2 at https://pr20850-a024bb2.ngbuilds.io/.

@mary-poppins

Copy link
Copy Markdown

You can preview 38258e1 at https://pr20850-38258e1.ngbuilds.io/.

@mary-poppins

Copy link
Copy Markdown

You can preview 7bd76e1 at https://pr20850-7bd76e1.ngbuilds.io/.

@mary-poppins

Copy link
Copy Markdown

You can preview cf724a4 at https://pr20850-cf724a4.ngbuilds.io/.

@mary-poppins

Copy link
Copy Markdown

You can preview 8e1cd1c at https://pr20850-8e1cd1c.ngbuilds.io/.

@LinboLen

LinboLen commented Jan 5, 2018

Copy link
Copy Markdown

I can't understand title. I have a little knowledge about tree shakable. can anyone explain tree shakable injectors

@trotyl

trotyl commented Jan 5, 2018

Copy link
Copy Markdown
Contributor

@LinboLen It make dropping unused injectables(services) possible for size saving purpose. (In combining with proper JavaScript bundler)

@mary-poppins

Copy link
Copy Markdown

You can preview 4f5c60c at https://pr20850-4f5c60c.ngbuilds.io/.

@tinayuangao tinayuangao added action: merge The PR is ready for merge by the caretaker target: patch This PR is targeted for the next patch release labels Jan 8, 2018
@mary-poppins

Copy link
Copy Markdown

You can preview 5b0759a at https://pr20850-5b0759a.ngbuilds.io/.

@mary-poppins

Copy link
Copy Markdown

You can preview 7b02a73 at https://pr20850-7b02a73.ngbuilds.io/.

@mary-poppins

Copy link
Copy Markdown

You can preview d5e098e at https://pr20850-d5e098e.ngbuilds.io/.

@IgorMinar IgorMinar added state: blocked and removed action: merge The PR is ready for merge by the caretaker labels Jan 9, 2018
@IgorMinar

Copy link
Copy Markdown
Contributor

We should merge this only after 5.2.0 is cut on Wednesday.

@mary-poppins

Copy link
Copy Markdown

You can preview dbf6255 at https://pr20850-dbf6255.ngbuilds.io/.

@ngbot

ngbot Bot commented Jan 24, 2018

Copy link
Copy Markdown

Hi @tinayuangao! This PR has merge conflicts due to recent upstream merges.
Please help to unblock it by resolving these conflicts. Thanks!

@trotyl

trotyl commented Feb 16, 2018

Copy link
Copy Markdown
Contributor

Superseded by #22005.

@mhevery

mhevery commented Feb 17, 2018

Copy link
Copy Markdown
Contributor

Closing this PR since @alxhub has taken over.

@mhevery mhevery closed this Feb 17, 2018
@angular-automatic-lock-bot

Copy link
Copy Markdown

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 Sep 13, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area: core Issues related to the framework runtime cla: yes state: blocked target: patch This PR is targeted for the next patch release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

10 participants