Advanced composition
In Chapter 5, Durandal – the Knockout Framework, we covered the basic and common uses of Durandal's composition system. This section will cover further composition techniques such as caching, transitions, and composition mode.
View caching
By default, the view rendered by the composition binding is discarded when the composed module is changed. This results in the DOM contents of the composition binding always being only the current module's view. The cacheView
option on the composed binding will change this behavior so that Durandal can keep any view composed. If a module is reactivated using the same object that is already bound to a view, it will not be recreated. Both the compose
and router
bindings have this option:
<div class="page-host"> <!-- ko router: { cacheViews: false }--> <!-- /ko --> </div>
You can see an example of this in the cp6-cache
branch. If you open the console, you can see that the attaching and binding events are no longer...