google-closuregoogle-closure-librarygoogle-closure-templates

Preferred method of recursive decoration in Closure


I'm looking for a way to take a document fragment (generated from a Soy template) in Google Closure and recursively decorate any elements with corresponding UI Components in the registry.

It seems to me that this should be relatively simple to achieve with a function that traverses the DOM, checks classes against the registry and decorates if appropriate, but this seemed like such a fundamental use case that I was wondering if I'm missing something simple.

Should I go ahead with my planned implementation, or is there a function somewhere in the library that handles this somewhere?

Alternatively, is my overall approach of decorating a template flawed? My intention is to be able to design complex components from a library of UI Components declaratively in Soy, using minimal JavaScript.


Solution

  • Yes, the library does nto support this out of the box, maybe some internal google code does, but I think they might have favoured a less full on approach for more control.

    our approach has been more multiphased i will explain it a bit.

    given that we want to use prerendering (as much as possible) our json data should map 1 to 1 to our templates, as such our json files provide a schema against which we generate our javascript which keeps our models up to date, creates our components (which you can extend by registering it with a factory and which then registers for decoration). this generated code then has a decorateChildren step which is automatically invoked when the component decorates and as such we get recursion. we actually also generate templates which are extendable then through the use of delegate template overrides (an awesome feature of the template system IMO)

    I think you are on the right track already, you just have to write some code to fit your needs.