In May 2018 I spent a few days exploring what it would take to remove can-view-nodelist from CanJS. The attempt stems from canjs/can-observation#125
The idea is to be able to automatically teardown observations that are created within templates when an outer observation updates itself. This would prevent needing to use nodelists to teardown observations.
The code for this looks like:
var stopTrap = observation.trapBindings();
canReflect.onValue(observation, function(){});
ObservationRecorder.addBindings(stopTrap());
This keeps a record of bindings within the observation record. Later, when you update an observation it will unbind all of these bindings.
Later it was discovered that something similar was needed for can-diff/patcher/patcher
and can-view-scope
.
The changes related to the above is in:
- https://github.com/canjs/can-observation/tree/tear
- https://github.com/canjs/can-observation-recorder/tree/adding-bindings
- https://github.com/canjs/can-diff/tree/destroy
Important, currently can-diff contains duplicate code for what can-observation has. This should be moved into a mixin they both can use (and likely can-view-scope.
- Move the bindings changes into a mixin, probably within can-event-queue.
- Update can-observation, can-diff/patcher/patcher to use this new mixin. Add the same functionality to can-view-scope.
The other thing that using can-view-nodelists provides is a way to keep track of nodes that are inserted within a section. Removing cann-view-nodelist from can-view-live.html presented a problem for this:
The #foo
live.html code doesn't know about the labels and therefore won't remove them if foo
is set to undefined.
To fix this we have discussed having can-stache creating placeholders. This would give us the start and end placeholder textnodes. From that we would know to replace all of the nodes in between.
Here are the changes so far to can-view-live and can-stache: