Most languages have some form of runtime dispatch but in elm you have to 
write it yourself, so it's up to you to choose a dispatch model.

A couple of patterns for this:

https://medium.com/@debois/elm-components-3d9c00c6c612#.hht7utwro
https://medium.com/@prozacchiwawa/the-im-stupid-elm-language-nugget-13-84ba8539ebc4#.xys1owh5e

On Saturday, February 18, 2017 at 3:20:59 AM UTC-8, Steffen wrote:
>
> To avoid the XY pitfall, here's some more context:
>
> I'm building a web scraper. It scans a number of websites for a fixed set 
> of data which is the same for all sites. The "driver" to access the sites 
> is site-specific and carries some state.
>
> The model looks like this:
>
>
> type SiteDriver
>     = Site1Driver Site1.Model
>     | Site2Driver Site2.Model
>
>
> type alias SiteModel =
>     { name : String
>     , datum1 : String
>     , datum2 : Int
>     , enabled : Bool
>     , driver : SiteDriver
>     }
>
>
> init : List SiteModel
> init =
>     [ { name = "Site 1"
>       , datum1 = ""
>       , datum2 = 0
>       , enabled = True
>       , driver = Site1Driver Site1.init
>       }
>     , { name = "Site 2"
>       , datum1 = ""
>       , datum2 = 0
>       , enabled = True
>       , driver = Site2Driver Site2.init
>       }
>     ]
>
>
> The list of SiteModels is fixed, they are just enabled or disabled as 
> necessary. This approach works fine for rendering HTML without code 
> duplication but I can't get updates to work...
>
> Thanks for watching.
>
> Sincerely,
> Steffen
>
>
>
> On Saturday, 18 February 2017 04:57:45 UTC+1, Steffen wrote:
>>
>> Hello,
>>
>> I'm new to Elm and stuck with a problem. In my model I have a list of 
>> components of different types. Now I'm trying to get the view and update 
>> functions right.
>>
>> This has surely already been solved, but I didn't find a solution 
>> anywhere...
>>
>> Minimal example:
>>
>> https://ellie-app.com/qsQjTYcs2va1/3
>>
>> Uncomment line 166 to see what I mean. I would need to "cast" 
>> ComponentMessage and -Model to their Int subtypes.
>>
>> What did I get wrong?
>>
>> Sincerely,
>> Steffen
>>
>

-- 
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