Skip to content

fix(ivy): support static ViewChild and ContentChild queries - #28811

Closed
kara wants to merge 6 commits into
angular:masterfrom
kara:static-queries
Closed

kara wants to merge 6 commits into
angular:masterfrom
kara:static-queries

Conversation

@kara

@kara kara commented Feb 19, 2019 •

Copy link
Copy Markdown
Contributor

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 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 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
Comment thread packages/core/src/render3/query.ts Resolved
Comment thread packages/core/src/render3/query.ts Resolved
Comment thread packages/core/src/render3/state.ts Resolved
kara added 2 commits February 19, 2019 13:01
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.

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

@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

kara commented Feb 19, 2019

Copy link
Copy Markdown
Contributor Author

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

kara commented Feb 19, 2019

Copy link
Copy Markdown
Contributor Author

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

5 participants