complate / complate-stream

complate's core library for rendering HTML via JSX
https://complate.org
6 stars 7 forks source link

`renderView` should accept optional `...children` #36

Open tillsc opened 5 years ago

tillsc commented 5 years ago

There should be an additional parameter ...children in renderView to allow passing children from somewhere else into the view-macro. This can be useful when utilizing external layout mechanisms like done in complate-ruby.

FND commented 5 years ago

🤔 Could you elaborate on this, perhaps provide a minimal example (doesn't need to be executable; just some pseudo-code to illustrate the use case)?

In my current understanding, I consciously distinguish view macros from component macros. The former never receive any children because it's a regular function call from the host environment, passing a view model (typically just an object, really) which constitutes the interface between both worlds. Where's the advantage in moving some of the parameters from the view model into a separate argument?

tillsc commented 5 years ago

Take a look at the current ruby adapter beta: https://github.com/complate/complate-ruby/blob/cb71489761849812411839050f80b4cc6607cebb/test/dummy_app/app/views/layouts/jsx_layout.html.jsx#L13 The current version allows us to make use of the Rails internal layout mechanism. This means rails renders the view first and renders the layout afterwards passing in the view's output (using a block yield in classic Rails ERP layouts). I just want to support this without making use of a hack like a parameter content as seen as in the example above.

FND commented 5 years ago

So if I understand this correctly, Rails has two separate render invocations: Once for the resource's main content, which is then wrapped in the generic layout.

That's probably not uncommon, so we should indeed support that - thank you.

tillsc commented 5 years ago

That is the reason why most rendering engines do not support proper chunking. complate-ruby also looses this ability when being used in this mode.