marschro
marschro

Reputation: 791

Architectural structure of elm modules with dependant models

I am currently digging deeper into elm and stumbled over the following Problem:

Now someone told me that every droid is owned by a Jedi (dont know if thats true). So I want to add a select box to the droids module - so I can assign a Droid to a Jedi. The Jedi's available for assignment shall be taken from the Jedis Model.

My first thougt was: Oh nice, I just import the main module in the droids module and try to extract my jedis. But that does not work, because of circularity in module dependencies.

Next I thought: I import the jedi model in the droids model and enhance my droids model with that - so I can get my jedis into the select box for the "droid-owners". But that does not work either. When I update the jedis list there are no effects in my droids module (that is logic, because the Messages generated by jedis are poppeled upwards to main. Main recognizes them and updates the main module. But the droids model will never recognise updates in the jedis module).

So I think I have to understand some more fundamentals on architectures in elm. I think I break the whole elm architecture.

Can anybody explain how this should be properly realised - I think that is a fundamental issue to understand before start developing larger Apps.

Here a screenshot. You can see the Models of those as a String below every component

Screenshot

Would appreciate some comments or hints or where to read more about... Thanks :-)

UPDATE

I have all three files in a gist: https://gist.github.com/marschro/7584216d5bdfed077b26a9d32c5b5cf6

Upvotes: 1

Views: 119

Answers (1)

Jonathan Fishbein
Jonathan Fishbein

Reputation: 526

Pass model.jedis to Droids.view from Main.view. You will have to modify Droids.view to accept an additional argument of List Jedi. Documentation on the core Elm functions can be confusing. They all have a default signature i.e.

view : Model -> Html Msg

but that is just the most basic signature. For this example modify it to be

view : List Jedi -> Model -> Html Msg

now you have the most up to date list of Jedis As far as module references you can do

import Jedi exposing (Jedi)

from your Droid module

Upvotes: 0

Related Questions