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(ivy): support static ViewChild and ContentChild queries #28811

Closed
wants to merge 6 commits into from

Conversation

kara
Copy link
Contributor

@kara kara commented Feb 19, 2019

This PR adds support for the static: true flag in
ViewChild and ContentChild queries. Prior to this commit, all
queries were resolved after change detection ran. This is
a problem for backwards compatibility because View Engine
also supported "static" queries which would resolve before
change detection.

Now if users add a static: true option, the query will be
resolved in creation mode (before change detection runs).
For example:

@ContentChild(TemplateRef, {static: true}) template !: TemplateRef;

This feature will come in handy for components that need
to create components dynamically.

Note: This PR also removes the optional arguments from
query instructions as additional perf cleanup.

@kara kara added state: WIP target: major This PR is targeted for the next major release comp: ivy labels Feb 19, 2019
@kara kara requested review from a team as code owners February 19, 2019 01:39
@ngbot ngbot bot added this to the needsTriage milestone Feb 19, 2019
@kara kara force-pushed the static-queries branch 2 times, most recently from e29b9d1 to 65a3957 Compare February 19, 2019 02:19
@kara kara requested a review from a team as a code owner February 19, 2019 02:19
@kara kara changed the title WIP: fix(ivy): support static ViewChild queries WIP: fix(ivy): support static ViewChild and ContentChild queries Feb 19, 2019
@kara kara force-pushed the static-queries branch 2 times, most recently from 1129f5f to 681bcae Compare February 19, 2019 04:46
@kara kara changed the title WIP: fix(ivy): support static ViewChild and ContentChild queries fix(ivy): support static ViewChild and ContentChild queries Feb 19, 2019
@kara kara added action: review The PR is still awaiting reviews from at least one requested reviewer and removed state: WIP labels Feb 19, 2019
@jelbourn jelbourn self-requested a review February 19, 2019 19:45
packages/compiler/src/render3/view/api.ts Show resolved Hide resolved
packages/compiler/src/render3/view/compiler.ts Outdated Show resolved Hide resolved
packages/compiler/src/render3/view/compiler.ts Outdated Show resolved Hide resolved
packages/core/src/render3/instructions.ts Show resolved Hide resolved
packages/core/src/render3/query.ts Outdated Show resolved Hide resolved
packages/core/src/render3/query.ts Outdated Show resolved Hide resolved
packages/core/src/render3/state.ts Outdated Show resolved Hide resolved
This commit adds support for the `static: true` flag in
`ViewChild` queries. Prior to this commit, all `ViewChild`
queries were resolved after change detection ran. This is
a problem for backwards compatibility because View Engine
also supported "static" queries which would resolve before
change detection.

Now if users add a `static: true` option, the query will be
resolved in creation mode (before change detection runs).
For example:

```ts
@ViewChild(TemplateRef, {static: true}) template !: TemplateRef;
```

This feature will come in handy for components that need
to create components dynamically.
This commit adds support for the `static: true` flag in `ContentChild`
queries. Prior to this commit, all `ContentChild` queries were resolved
after change detection ran. This is a problem for backwards
compatibility because View Engine also supported "static" queries which
would resolve before change detection.

Now if users add a `static: true` option, the query will be resolved in
creation mode (before change detection runs). For example:

```ts
@ContentChild(TemplateRef, {static: true}) template !: TemplateRef;
```

This feature will come in handy for components that need
to create components dynamically.
Copy link
Member

@jelbourn jelbourn left a comment

Choose a reason for hiding this comment

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

LGTM

@kara kara added action: merge The PR is ready for merge by the caretaker merge: caretaker note Alert the caretaker performing the merge to check the PR for an out of normal action needed or note and removed action: review The PR is still awaiting reviews from at least one requested reviewer labels Feb 19, 2019
@kara
Copy link
Contributor Author

kara commented Feb 19, 2019

merge-assistance: there are no longer any public API changes after rebase. The reviewer was requested when this PR still contained the public API changes in #28810.

@kara
Copy link
Contributor Author

kara commented Feb 19, 2019

presubmit

@kara kara removed the merge: caretaker note Alert the caretaker performing the merge to check the PR for an out of normal action needed or note label Feb 19, 2019
@IgorMinar IgorMinar closed this in a4638d5 Feb 19, 2019
IgorMinar pushed a commit that referenced this pull request Feb 19, 2019
This commit adds support for the `static: true` flag in `ContentChild`
queries. Prior to this commit, all `ContentChild` queries were resolved
after change detection ran. This is a problem for backwards
compatibility because View Engine also supported "static" queries which
would resolve before change detection.

Now if users add a `static: true` option, the query will be resolved in
creation mode (before change detection runs). For example:

```ts
@ContentChild(TemplateRef, {static: true}) template !: TemplateRef;
```

This feature will come in handy for components that need
to create components dynamically.

PR Close #28811
@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 Sep 14, 2019
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 cla: yes target: major This PR is targeted for the next major release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants