How to Get Elm Like Accessors for Messages in Bucklescript-TEA
When you create Msgs in Elm like this:
type Msg
= UpdateText String
You automatically get an access function like this:
UpdateText : String -> Msg
UpdateText str =
UpdateText str
Which can be used for an onInput
in a text box:
onInput : (String -> msg) -> Attribute msg
and applied like this:
input [ type_ "text", value model.content, onInput UpdateText ] []
In Bucklescript-TEA, to get the same thing, you need this:
[@@bs.deriving accessors]
type msg
= UpdateText of String
[@@bs.deriving accessors]
Which would give you this function starting with a lowercase letter:
val updateText : string -> msg
let updateText str =
UpdateText str
And then can be used like this:
input' [ type' "text", value model.content, onInput updateText ] []
and return in the update
function like this:
let update msg model =
match msg with
| UpdateText str -> { model with inputBox = str }