waneck / mweb

2 stars 3 forks source link

Idea: support the return of concatenated (or, more generally, multiple) templates #6

Open jonasmalacofilho opened 9 years ago

jonasmalacofilho commented 9 years ago

Since mweb only executes the template after all routes have been executed, it would be nice to have a way to return more than one view but keeping their data separate.

Surely a proper hierarchy can achieve more complex schemes, but even a simple concatenation of multiple views could be useful: this way, the actual data and its auxiliary information (some as variable data on the <head>) could be kept separate in the route execution and could be cleanly extracted later by, for instance, a generic html to api converter (that is, a serializer).

What do you think?

var header = new TemplateLink({ title : "Some page title" }, headerView);
var rest = new TemplateLink({ ... actual data ... }, bodyView);
return HttpResponse.fromContent([header, rest]);
waneck commented 9 years ago

The only problem I see is how HttpResponse would be typed in this example. As far as I see, we'd need either to make a macro that would merge anonymous types' definitions, or we'd need to fall through Dynamic. Any ideas?