Thank you Anthony for your comments and here comes my clarification.

You are right that, adding response.files within a component, has no
effect at all when called by "component.load". But I still keep a copy
of those response.files inside the component, because they are needed
when visiting "component.html" (during developing or debugging phase).

On the other hand, when we have to copy those response.files in action
"skeleton" or action "index", that does not feel elegant, because
action "index" has to explicitly include some helper resources which
not needed by itself. Imagine that, after I change implementation of
"component" later, I have to modify "index" also. Grrr.

Pbreit's suggestion is what I can do right now (thank you Pbreit too),
it is DRY, but still not solving the unnecessary coupling mentioned
above.

Regards,
Iceberg


On May 7, 11:04 pm, Anthony <abasta...@gmail.com> wrote:
> Does adding to response.files within a component controller work at all?
> With ajax=False, it looks like LOAD creates a new environment (and response)
> to run the component controller, so I'm not sure appending to response.files
> within a component controller will affect the response.files of the parent
> controller.
>
> response.files is only used by web2py_ajax.html, which is typically included
> in layout.html. Your index view probably extends layout.html, so
> response.files added within the index controller will get included by
> web2py_ajax.html. However, your component .load views probably do not extend
> layout.html, so I would guess response.files added within component
> controllers would be ignored.
>
> Haven't tried it, though, so I may be missing something.
>
> Anthony
>
>
>
>
>
>
>
> On Saturday, May 7, 2011 9:52:27 AM UTC-4, Iceberg wrote:
> > Hi Massimo,
>
> > Can web2py support chaining response.files inside a component?
>
> > Scenario.
>
> > def component():
> >     response.files.extend([
> >         URL(..., 'fancy_helper1.js'),
> >         URL(..., 'fancy_helper2.js'),
> >         ......,
> >         URL(..., 'fancy_helper10.js'),
> >         ])
> >     return {'': 'Some fancy stuff'}
>
> > def skeleton():
> >     response.files.extend([
> >         URL(..., 'fancy_helper1.js'),
> >         URL(..., 'fancy_helper2.js'),
> >         ......,
> >         URL(..., 'fancy_helper10.js'),
> >         ]) # SAME AS THOSE IN component(). Can I omit this?
> >     return {'': LOAD('default', 'component.load', ajax=False)}
>
> > def index():
> >     response.files.extend([
> >         URL(..., 'fancy_helper1.js'),
> >         URL(..., 'fancy_helper2.js'),
> >         ......,
> >         URL(..., 'fancy_helper10.js'),
> >         ]) # SAME AS THOSE IN component(). Can I omit this?
> >     return {'': LOAD('default', 'skeleton.load', ajax=False)}
>
> > Currently, if I add one more helper_extra.js into my fancy
> > component(), I needed to duplicate them into skeleton() and index().
> > It is not DRY. Can it be improved?
>
> > Regards,
> > Ray Luo (Iceberg)

Reply via email to