On Wednesday, October 12, 2016 at 1:55:02 PM UTC+1, Peter Damoc wrote:
>
> Needing to set state on a component feels like an anti-pattern. 
>

I agree in that I haven't thought of a use case for it yet that is better 
than the declarative alternative. But worth pointing out as a limitation on 
Elm webcomponents, vs webcomponents without Elm as this is something that 
can easily be done in javascript.

Also if a webcompnent written in Elm is to be used outside of Elm as a true 
webcomponent, it will be possible to provide methods to read and write its 
state from javascript, because we have the port to set state on it from 
Elm, and can use a subscription to read state into Elm (haven't tried that 
one yet, I took the reset method out for now).

There was one area I was thinking it might be needed relating to lifecycle 
events on the component. Suppose a consumer of a component wants to close 
it down - does it need to be able to set "state = closed" on it? 

But I think simply removing it from the view should trigger the 
'detached()' state transition on the component? In which case that solves 
that issue. 

I should try that one out by putting some logging code in the detached() 
lifecycle method.

===

This limitation means you can't have UI elements defined outside of a 
component affect its state. Suppose you had a video component and a video 
control bar compnent, you could not make those separate components, you'd 
always have to embed the control bar inside the video component. Sounds ok 
though, it means that a component is more truly independant. 

I think though it might make letting the consumer of the video component 
customize its control bar difficult. I might like to do something like this

video [ src "http://myvids.com/cute_cats.mpg"; ]
[ videoControl [] [ button [ onclick Pause ] [ text "pause" ] ] ]

Now how does the Pause action tell the video to pause?

So perhaps some way of passing an id into a port and having it look up the 
component to invoke might be needed.

-- 
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 elm-discuss+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to