Skip to content

PATCH backport: refactor(compiler): move injector factory - #41133

Closed
petebacondarwin wants to merge 2 commits into
angular:11.2.xfrom
petebacondarwin:compiler-injector-factory-refactor-patch-2
Closed

petebacondarwin wants to merge 2 commits into
angular:11.2.xfrom
petebacondarwin:compiler-injector-factory-refactor-patch-2

Conversation

@petebacondarwin

Copy link
Copy Markdown
Contributor

This is a backport of #41022 since it had conflicts on 11.2.x

…Injector()` (angular#41022)

This commit moves the creation of the injector's factory function
out so that it can be more easily refactored further.

PR Close angular#41022
@google-cla google-cla Bot added the cla: yes label Mar 9, 2021
@petebacondarwin petebacondarwin added action: review The PR is still awaiting reviews from at least one requested reviewer area: compiler Issues related to `ngc`, Angular's template compiler area: core Issues related to the framework runtime compiler: linker engine: ivy target: patch This PR is targeted for the next patch release labels Mar 9, 2021
@ngbot ngbot Bot modified the milestone: Backlog Mar 9, 2021
…41022)

Previously, injector definitions contained a `factory` property that
was used to create a new instance of the associated NgModule class.

Now this factory has been moved to its own `ɵfac` static property on the
NgModule class itself. This is inline with how directives, components and
pipes are created.

There is a small size increase to bundle sizes for each NgModule class,
because the `ɵfac` takes up a bit more space:

Before:

```js
let a = (() => {
  class n {}
  return n.\u0275mod = c.Cb({type: n}),
  n.\u0275inj = c.Bb({factory: function(t) { return new (t || n) }, imports: [[e.a.forChild(s)], e.a]}),
  n
})(),
```

After:

```js
let a = (() => {
  class n {}
  return n.\u0275fac = function(t) { return new (t || n) },
  n.\u0275mod = c.Cb({type: n}),
  n.\u0275inj = c.Bb({imports: [[r.a.forChild(s)], r.a]}),
  n
})(),
```

In other words `n.\u0275fac = ` is longer than `factory: ` (by 5 characters)
and only because the tooling insists on encoding `ɵ` as `\u0275`.

This can be mitigated in a future PR by only generating the `ɵfac` property
if it is actually needed.

PR Close angular#41022
@petebacondarwin
petebacondarwin force-pushed the compiler-injector-factory-refactor-patch-2 branch from fdd78f5 to 4ae9951 Compare March 9, 2021 10:38
@petebacondarwin
petebacondarwin marked this pull request as ready for review March 9, 2021 11:58
@pullapprove
pullapprove Bot requested a review from AndrewKushnir March 9, 2021 11:58

@AndrewKushnir AndrewKushnir 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.

LGTM 👍

Note: since this is a backport of the changes from #41022 (which had conflicts merging to the patch branch), no further reviews are needed (all approvals were received within #41022).

@AndrewKushnir AndrewKushnir added action: merge The PR is ready for merge by the caretaker PullApprove: disable and removed action: review The PR is still awaiting reviews from at least one requested reviewer labels Mar 9, 2021
@AndrewKushnir

Copy link
Copy Markdown
Contributor

Closed by commit 1bebd66

AndrewKushnir pushed a commit that referenced this pull request Mar 9, 2021
…Injector()` (#41022) (#41133)

This commit moves the creation of the injector's factory function
out so that it can be more easily refactored further.

PR Close #41022

PR Close #41133
AndrewKushnir pushed a commit that referenced this pull request Mar 9, 2021
…41133)

Previously, injector definitions contained a `factory` property that
was used to create a new instance of the associated NgModule class.

Now this factory has been moved to its own `ɵfac` static property on the
NgModule class itself. This is inline with how directives, components and
pipes are created.

There is a small size increase to bundle sizes for each NgModule class,
because the `ɵfac` takes up a bit more space:

Before:

```js
let a = (() => {
  class n {}
  return n.\u0275mod = c.Cb({type: n}),
  n.\u0275inj = c.Bb({factory: function(t) { return new (t || n) }, imports: [[e.a.forChild(s)], e.a]}),
  n
})(),
```

After:

```js
let a = (() => {
  class n {}
  return n.\u0275fac = function(t) { return new (t || n) },
  n.\u0275mod = c.Cb({type: n}),
  n.\u0275inj = c.Bb({imports: [[r.a.forChild(s)], r.a]}),
  n
})(),
```

In other words `n.\u0275fac = ` is longer than `factory: ` (by 5 characters)
and only because the tooling insists on encoding `ɵ` as `\u0275`.

This can be mitigated in a future PR by only generating the `ɵfac` property
if it is actually needed.

PR Close #41022

PR Close #41133
@petebacondarwin
petebacondarwin deleted the compiler-injector-factory-refactor-patch-2 branch March 10, 2021 12:50
@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 Apr 10, 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: compiler Issues related to `ngc`, Angular's template compiler area: core Issues related to the framework runtime cla: yes compiler: linker PullApprove: disable target: patch This PR is targeted for the next patch release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants