xmlet/HtmlFlow

Misunderstanding of how to use printStream to stream html

pedromvu opened this issue · 2 comments

So I had everything working using render(), when I ran into issues and decided to change to output into a file when I realized just adding the printStream and calling write at the end didn't work.

Debugging the code I realized all the builder code is executing everything eagerly building some StringBuilder as you add html tags, and all the buffer gets discarded as soon as I call setPrintStream.

So the only solution I found was to set the printStream right before I start building the Html:

var view = (HtmlView<?>) StaticHtml.view().setPrintStream(ps); var html = view.html();

But not sure the method returns a less specific type, thats why I had to add the cast, but in the end it works.

Is this how it is supposed to work? because from the documentation I assumed you could decide how to render it at the end, and so I assumed everything would run lazily like Java streams.

So decided to check the tests and realized that for html to build lazily I need to use the version of view() that takes a consumer, also that there is a version that takes the printStream to avoid needing the cast if I used my current approach, I guess I didn't read the documentation properly.

Please let me know If is is there any section of documentations that you think that should be clarified!

The documentation has been built from an implementation point of view and it lacks some feature details from an end user view.

I will try to improve the documentation with users suggestions.