Hi, i have a problem to decode a event object on my custom event listener. I created an “onLoad” event and pass Bar, which is a Msg of type Int, as a tagger function. When i run barDecoder as my decoder in my custom onLoad function, it works like expected.
Now i want to extract more information from my event object, so i make a type alias named ImageData which is a record. Now, i pass the Msg type Foo to my onLoad function and i run into a compiler error:
This
Foo
value is a:
ImageData → Msg
ButonLoad
needs the 1st argument to be:
Int → msg
type alias Model =
{ simple: Int
, data: ImageData
}
type Msg
= Bar Int
| Foo ImageData
init =
Model
0
{height = 0}
type alias ImageData =
{ height: Int
}
onLoad tagger =
on "load" ( Decode.map tagger fooDecoder)
barDecoder =
Decode.field "target" (Decode.field "naturalHeight" Decode.int)
fooDecoder =
Decode.field "target" (Decode.field "naturalHeight" Decode.int)
img [ src "watch.png", onLoad Foo ][]