http://elm-community.github.io/elm-faq/#why-when-i-import-a-module-that-defines-a-type-does-the-compiler-know-about-the-type-name-but-not-its-constructors
2016-05-30 8:44 GMT+02:00 David <[email protected]>: > Thank you, Peter. You've described a nice solution. > > The problem I'm having, though is that when I try to send Child2.someMsg the > compiler tells me that `Child2` does not expose `someMsg`. I am, however > exposing it in the module shown in the code below. > > How does one create a Msg to then send to Child2? It appears that even > though it's exposed it's not recognized in the parent module. > > Relevant code: > > module Child2 exposing (Msg, Model, view, update, model) > ... > > -- Msg Union Type Definition Child2 > > type Msg = > SomeMsg > | NoOp > > > > > On Monday, May 30, 2016 at 1:22:26 AM UTC-5, Peter Damoc wrote: >> >> You have multiple ways to address this, depending on the role or the ID. >> >> If the ID is just an identifier of the child, it should not be in the >> child because it has nothing to do with the child functionality. It should >> be in the parent, similar to the way CounterList is implemented in the >> tutorial. Once it is in the parent, your problem becomes very simple since >> you will have access to the ID in the parent `update` >> >> If, for some reason, you need to keep the id inside the child, you can >> expose an interrogation API on the model >> >> case of msg >> UpdateFromChild1 msg -> >> let >> newChild1 = Child1.update msg model.child1 >> id = Child1.id model.child1 >> c2msg = Child2.someMsgForId id >> newChild2 = Child2.update c2msg model.child2 >> in >> { model | child1 = newChild1, child2 = newChild2 } >> >> And in Child1.elm have >> >> id model = model.id >> >> in Child2.elm have >> >> someMsgForId id = SomeMsg id >> >> Approaching things like this ensure that you are not needlessly coupling >> Child1 and Child2 code. >> >> >> >> >> >> >> On Mon, May 30, 2016 at 4:06 AM, David <[email protected]> wrote: >> >>> Hi, >>> >>> I'm new at this too and just experimenting. The model structured is >>> presented below. I don't think it has much to do with the model, but more >>> to do with the fact that the update in Child2 is expecting a Child2.Msg, >>> but is instead receiving a Child1.Msg. >>> >>> Model Child2 >>> --- >>> model = >>> { id: Int >>> , name: String >>> , description: String >>> } >>> >>> >>> >>> On Sunday, May 29, 2016 at 4:12:59 PM UTC-5, Witold Szczerba wrote: >>>> >>>> Hi, >>>> I am just experimenting with Elm, haven't done anything yet, so I will >>>> be watching how this thread evolves. Looking at your case, I have but one >>>> question: what's the model of the component you have problem with? >>>> >>>> Regards, >>>> Witold Szczerba >>>> 29 maj 2016 21:06 "David" <[email protected]> napisał(a): >>>> >>>> I need to update 2 child components based on the Action/Msg of 1 child >>>> component. How would I do this? >>>> >>>> The UpdateFromChild1 contains a Child1.Msg, which contains an id. I'd >>>> like to send the id to the models of Child1 update *and* to Child2 >>>> update. >>>> >>>> Code: >>>> >>>> Main update >>>> --- >>>> update msg model = >>>> case of msg >>>> UpdateFromChild1 msg -> >>>> Child1.update msg Child1.model <---- works, update gets correct >>>> message with id >>>> Child2.update *msg* Child2.model <---- does not work, obviously >>>> ^---------------------- somehow change this to >>>> (Child2.Msg id)? >>>> UpdateFromChild2 msg -> >>>> -- stuff only child 2 cares about >>>> >>>> >>>> >>>> Main view >>>> --- >>>> view model = >>>> div [] >>>> [ App.map UpdateFromChild1 (Child1.view Child1.model) >>>> , App.map UpdateFromChild2 (Child2.view Child2.model) >>>> ] >>>> >>>> -- >>>> 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. >>>> >>>> -- >>> 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. >>> >> >> >> >> -- >> There is NO FATE, we are the creators. >> blog: http://damoc.ro/ >> > -- > 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. > -- 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.
