Files
Andrew Scott 9b65b84cb9 feat(core): Mark components for check if they read a signal (#49153)
This commit updates the `LView` in Angular to be a `Consumer` of
signals. If a signal is read when executing a template, it marks the
view dirty. In addition, if a signal is read when executing host
bindings, it also marks views dirty.

One interesting thing about signal reads in host bindings
is that they perform a bit better than what we can do with today's
APIs. In order to re-execute host bindings for an `OnPush` component that
might have changed, you would probably inject `ChangeDetectorRef` and call
`markForCheck`. This will mark the _current component_ and parents
dirty. However, host bindings are executed as part of refreshing the
_parent_ so there is really no need to re-execute the current component
if the only thing that changed is the host bindings. When a signal is
read in host bindings, it marks the parent dirty and not the component
that defined the host binding.

Additionally, this commit avoids allocating a full consumer for each
`LView` by re-using a consumer until template execution results in a
signal read. At this point, we assign that consumer to the `LView` and
create a new consumer to "tentatively" use for the future `LView`
template executions.

Co-authored-by: Dylan Hunn <github@dylanhunn.com>

PR Close #49153
2023-03-27 11:19:06 -07:00

79 lines
2.3 KiB
Python

load("//tools:defaults.bzl", "jasmine_node_test", "karma_web_test_suite", "ng_module", "ts_library")
package(default_visibility = ["//visibility:private"])
SPEC_FILES_WITH_FORWARD_REFS = [
"di_forward_ref_spec.ts",
]
ts_library(
name = "acceptance_lib",
testonly = True,
srcs = glob(
["**/*.ts"],
exclude = SPEC_FILES_WITH_FORWARD_REFS,
),
# Visible to //:saucelabs_unit_tests
visibility = ["//:__pkg__"],
deps = [
"//packages/animations",
"//packages/animations/browser",
"//packages/animations/browser/testing",
"//packages/common",
"//packages/common/locales",
"//packages/compiler",
"//packages/core",
"//packages/core/src/signals",
"//packages/core/src/util",
"//packages/core/test/render3:matchers",
"//packages/core/testing",
"//packages/localize",
"//packages/localize/init",
"//packages/platform-browser",
"//packages/platform-browser-dynamic",
"//packages/platform-browser/animations",
"//packages/platform-browser/testing",
"//packages/platform-server",
"//packages/private/testing",
"//packages/router",
"//packages/zone.js/lib:zone_d_ts",
"@npm//rxjs",
],
)
# Note: The `forward_ref` example tests are built through this `ng_module` sub-target.
# This is done so that DI decorator/type metadata is processed manually by the compiler
# ahead of time. We cannot rely on the official TypeScript decorator downlevel emit (for JIT),
# as the output is not compatible with `forwardRef` and ES2015+. More details here:
# https://github.com/angular/angular/commit/323651bd38909b0f4226bcb6c8f5abafa91cf9d9.
# https://github.com/microsoft/TypeScript/issues/27519.
ng_module(
name = "forward_ref_test_lib",
testonly = True,
srcs = SPEC_FILES_WITH_FORWARD_REFS,
deps = [
"//packages/core",
"//packages/core/testing",
],
)
jasmine_node_test(
name = "acceptance",
bootstrap = ["//tools/testing:node"],
deps = [
":acceptance_lib",
":forward_ref_test_lib",
"//packages/zone.js/lib:zone_d_ts",
"@npm//base64-js",
"@npm//source-map",
],
)
karma_web_test_suite(
name = "acceptance_web",
deps = [
":acceptance_lib",
":forward_ref_test_lib",
],
)