The style-elements 
<http://package.elm-lang.org/packages/mdgriffith/style-elements/latest> 
package introduced at Elm Europe today needs to solve this problem too. For 
now, it too is just rendering an invalid <style> tag into the HTML body (see 
Element.InternalRender 
<https://github.com/mdgriffith/style-elements/blob/3.0.0/src/Element/Internal/Render.elm#L19-L29>
).

On Monday, June 5, 2017 at 8:46:47 PM UTC+10, Francesco Orsenigo wrote:
>
> I am experimenting with view functions that produce both html content and 
> the style that should be applied to that markup, as in
>
> myView : Model -> ( Html msg, List CssRule )
>
> So far, I have been rendering the above by creating a <style> tag inside 
> the <body>: this works great but it is not compliant, so I want to find a 
> way to insert the styling in the <head>.
>
> I can do this with a port, but where do I execute it?
>
> One solution would be to execute myView inside the program's update 
> cycle, store the resulting Html in the model, and have a dummy program 
> view function that just produces the pre-rendered html content stored in 
> the model, but seems a really weird thing to do and I don't know how it 
> would impact performance.
>
> update msg model =
>     let
>        ...
>
>         ( html, style ) = myView model
>     in
>         ( { model | renderedView = html }, portUpdateHeaderStyle style )
>
> view model =
>   model.renderedView
>
>
> The other solution would be to render everything twice, once in the 
> program's view to get the html content, and another inside the update cycle 
> to get the style and execute the port, but executing myView twice doesn't 
> seem great for performance.
>
> Is there a better way?
>

-- 
You received this message because you are subscribed to the Google Groups "Elm 
Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to