Refactor trackViews() to reliably remove views
Created by: lguychard
Fixes #4064
Refactors trackViews()
to stop relying on a ViewResolver
's selector to detect
removed views. We now inspect removedNodes
to see if any of the removed nodes
is a known view, or contains one or more known views.
With this refactor, the viewStates
logic is now encapsulated within trackViews()
,
which simply emits every added views as a ViewWithSubscriptions
, and takes care of calling
view.subscriptions.unsubscribe()
when the view is removed from the page. This prevents
the consumer from having to reimplement the viewStates
pattern.
Test plan: The view addition/removal logic is well tested by existing unit tests, but performance should be benchmarked as view removal is now more expensive.
TODO:
-
Fix remaining failing test handleContentViews() › detects addition, mutation, and removal of content views
-
Consider consolidating code_views.test.ts
withviews.test.ts