[elm-discuss] Re: view function to call other view function with different Msg type

2017-04-25 Thread David Legard

>
> Well, the problem is itemView can't be used , as it is 'Html ItemMsg', and 
> not 'Html Msg'
> However, the Item module doesn't have access to 'Msg' ( which is top level 
> ),
>

Whenever I run into that problem, I create a  separate file 
*MessageTypes.elm* with the Msg types in it and nothing else.

Then, all the other modules in the app import it, so that the Msg types are 
all available everywhere. Makes things much simpler.

module Main exposing (..)

import MessageTypes exposing (..)


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


Re: [elm-discuss] Re: view function to call other view function with different Msg type

2017-04-25 Thread Witold Szczerba
Maybe it will help you to know that I always return top level messages from
my views. Like this:

input
[ type_ "checkbox"
, checked form.queryAssignedOnly
, onCheck (Msg.PayoutList << PayoutMsg.UpdateQueryAssignedOnly)
]

Just for the record, the (Msg.PayoutList <<
PayoutMsg.UpdateQueryAssignedOnly)produces a new function, when called it
will invoke PayoutMsg and the result will be applied to Msg (top level).

Or another example from the same form:

[ button
[ type_ "button"
, onClick
(if RemoteData.isFailure form.list then
Msg.Reload
else
Msg.PayoutList PayoutMsg.RefreshForm
)

This button will either refresh my form using local PayoutMsg.RefreshForm or
it will call top-level Msg.Reload when errors were encountered previously.

Regards,
Witold Szczerba


On Tue, Apr 25, 2017 at 2:02 PM, Vardhan  wrote:

> Hi,
> On Monday, April 24, 2017 at 10:54:28 PM UTC+5:30, Erik Lott wrote:
>>
>> Whoops. Html.map is correct...
>>
>
>  Thanks for the answers.  However I later ``discovered`` that  the top Msg
> will have to include a id too ,
>  type Msg= ItemMsg IDType ItemMsg
>  .. so things got  more complicated.
> I guess i'll make flat app first, and them extract models.
>
> -Thanks
> Vardhan
>
>
>
>> view : Model -> Html Msg
>> view model =
>> div []
>> (model.items
>>   |> List.map itemView
>>   |> List.map (Html.map ItemMsg)
>> )
>>
>> On Sunday, April 23, 2017 at 1:49:22 PM UTC-4, Max Goldstein wrote:
>>>
>>> Yes, Ian is correct.
>>>
>>> Html.Attributes.map
>>> 
>>>  :
>>> (a -> msg) -> Attribute a -> Attribute msg
>>>
>>> Html.map
>>> : (a
>>> -> msg) -> Html a -> Html msg
>>>
>>
> On Monday, April 24, 2017 at 10:54:28 PM UTC+5:30, Erik Lott wrote:
>>
>> Whoops. Html.map is correct...
>>
>> view : Model -> Html Msg
>> view model =
>> div []
>> (model.items
>>   |> List.map itemView
>>   |> List.map (Html.map ItemMsg)
>> )
>>
>> On Sunday, April 23, 2017 at 1:49:22 PM UTC-4, Max Goldstein wrote:
>>>
>>> Yes, Ian is correct.
>>>
>>> Html.Attributes.map
>>> 
>>>  :
>>> (a -> msg) -> Attribute a -> Attribute msg
>>>
>>> Html.map
>>> : (a
>>> -> msg) -> Html a -> Html msg
>>>
>> --
> 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.
>

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


[elm-discuss] Re: view function to call other view function with different Msg type

2017-04-25 Thread Vardhan
Hi,
On Monday, April 24, 2017 at 10:54:28 PM UTC+5:30, Erik Lott wrote:
>
> Whoops. Html.map is correct... 
>

 Thanks for the answers.  However I later ``discovered`` that  the top Msg 
will have to include a id too , 
 type Msg= ItemMsg IDType ItemMsg
 .. so things got  more complicated. 
I guess i'll make flat app first, and them extract models.

-Thanks
Vardhan



> view : Model -> Html Msg
> view model =
> div []
> (model.items
>   |> List.map itemView 
>   |> List.map (Html.map ItemMsg)
> )
>
> On Sunday, April 23, 2017 at 1:49:22 PM UTC-4, Max Goldstein wrote:
>>
>> Yes, Ian is correct.
>>
>> Html.Attributes.map 
>> 
>>  : 
>> (a -> msg) -> Attribute a -> Attribute msg
>>
>> Html.map  
>> : (a 
>> -> msg) -> Html a -> Html msg
>>
>
On Monday, April 24, 2017 at 10:54:28 PM UTC+5:30, Erik Lott wrote:
>
> Whoops. Html.map is correct... 
>
> view : Model -> Html Msg
> view model =
> div []
> (model.items
>   |> List.map itemView 
>   |> List.map (Html.map ItemMsg)
> )
>
> On Sunday, April 23, 2017 at 1:49:22 PM UTC-4, Max Goldstein wrote:
>>
>> Yes, Ian is correct.
>>
>> Html.Attributes.map 
>> 
>>  : 
>> (a -> msg) -> Attribute a -> Attribute msg
>>
>> Html.map  
>> : (a 
>> -> msg) -> Html a -> Html msg
>>
>

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


[elm-discuss] Re: view function to call other view function with different Msg type

2017-04-24 Thread Erik Lott
Whoops. Html.map is correct... 

view : Model -> Html Msg
view model =
div []
(model.items
  |> List.map itemView 
  |> List.map (Html.map ItemMsg)
)

On Sunday, April 23, 2017 at 1:49:22 PM UTC-4, Max Goldstein wrote:
>
> Yes, Ian is correct.
>
> Html.Attributes.map 
> 
>  : 
> (a -> msg) -> Attribute a -> Attribute msg
>
> Html.map  
> : (a 
> -> msg) -> Html a -> Html msg
>

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


[elm-discuss] Re: view function to call other view function with different Msg type

2017-04-23 Thread Max Goldstein
Yes, Ian is correct.

Html.Attributes.map 
 
: 
(a -> msg) -> Attribute a -> Attribute msg

Html.map  
: (a -> 
msg) -> Html a -> Html msg

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


[elm-discuss] Re: view function to call other view function with different Msg type

2017-04-23 Thread Ian Mackenzie
Shouldn't that be Html.map, not Html.Attributes.map? itemView returns a Html 
msg, not an Html.Attribute msg...

On Saturday, 22 April 2017 21:53:47 UTC-4, Erik Lott wrote:
>
> view : Model -> Html Msg
> view model =
> div []
> (model.items
>   |> List.map itemView 
>   |> List.map (Html.Attributes.map ItemMsg)
> )
>
>
>
>
> On Saturday, April 22, 2017 at 5:25:41 PM UTC-4, Vardhan wrote:
>>
>> [ Pardon if this appear twice ]
>>
>> hi,
>>   this is my  toy 1st elm app.
>>i'm trying to keep the 'item' of the list as a seperet module.
>>
>> so i have in module Item:
>> -
>> type alias ItemModel= { ... }
>> type ItemMsg = .. | .. | ..
>> itemView : ItemModel -> Html ItemMsg
>> -
>>
>> And in the top level App  module:
>> -
>> type alias Model = { items: List ItemModel }
>> type Msg = ItemMsg ItemMsg | ...
>> view : Model -> Html Msg
>> view model =
>> div []
>> (List.map itemView model.items )
>> --
>>
>> Well, the problem is itemView can't be used , as it is 'Html ItemMsg', 
>> and not 'Html Msg'
>> However, the Item module doesn't have access to 'Msg' ( which is top 
>> level ),
>>
>> How should I use itemView in the view function ?
>>
>> -Regards
>> Vardhan
>>
>>
>>

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


[elm-discuss] Re: view function to call other view function with different Msg type

2017-04-22 Thread Erik Lott
view : Model -> Html Msg
view model =
div []
(model.items
  |> List.map itemView 
  |> List.map (Html.Attributes.map ItemMsg)
)




On Saturday, April 22, 2017 at 5:25:41 PM UTC-4, Vardhan wrote:
>
> [ Pardon if this appear twice ]
>
> hi,
>   this is my  toy 1st elm app.
>i'm trying to keep the 'item' of the list as a seperet module.
>
> so i have in module Item:
> -
> type alias ItemModel= { ... }
> type ItemMsg = .. | .. | ..
> itemView : ItemModel -> Html ItemMsg
> -
>
> And in the top level App  module:
> -
> type alias Model = { items: List ItemModel }
> type Msg = ItemMsg ItemMsg | ...
> view : Model -> Html Msg
> view model =
> div []
> (List.map itemView model.items )
> --
>
> Well, the problem is itemView can't be used , as it is 'Html ItemMsg', and 
> not 'Html Msg'
> However, the Item module doesn't have access to 'Msg' ( which is top level 
> ),
>
> How should I use itemView in the view function ?
>
> -Regards
> Vardhan
>
>
>

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