leonidas/transparency — Issue #11: DOM changes are not reflected into the template cache
Author: miohtama
Created: 2012-02-18 01:23:44+00:00
State: open

Though a rare scenario, there are situations where one would like to use different template for the same DOM node depending on the situation.

Currently Transparency explicitly caches the first applied template on any DOM node:

context.data('template', context.clone()) unless context.data 'template'

Meaning that if the context changes e.g. like this:

// Use different template for the empty cart
// than cart populated with items
if(data.count > 0) {
template = $("#checkout-popup-template");
} else {
// Empty :/
template = $("#checkout-popup-empty-template");
}
elem.empty();
elem.append(template.children());

The change is not automatically reflected.

Possible resolutions out of my head

1) Detect template changes in more smart way

2) Have an public API to explicitly set template (does not need to come from context itself)