leonidas / transparency

Transparency is a semantic template engine for the browser. It maps JSON objects to DOM elements by id, class and data-bind attributes.
http://leonidas.github.com/transparency/
MIT License
969 stars 112 forks source link

DOM changes are not reflected into the template cache #11

Open miohtama opened 12 years ago

miohtama commented 12 years ago

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 implicitly 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)

miohtama commented 12 years ago

A workaround is to explicitly set template (cache) before calling render()

        var template;

        // 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");
        }

        // Explicitly set Transparency template
        // https://github.com/leonidas/transparency/issues/11
        elem.data("template", template);
pyykkis commented 12 years ago

Workaround isn't valid anymore. I'll write a section to FAQ.

miohtama commented 12 years ago

Added a cache busting parameter to render(), should be merged?

https://github.com/miohtama/transparency/commit/03aa310019f53ff43b13a31c13b1b69db24e399a

hex commented 11 years ago

What's the status on the cache busting feature? Does it exist in transparency.js? Is there a way that you can disable caching?

untsop commented 11 years ago

I have just spent about 3 hours trying to solve this problem, and I didn't figure it out. Can anyone help me? l need it very badly.