I am very new and am currently trying to get to know Elma. I come from JS / React and have no previous RFP experience.
I'm in the Guide right here: http://guide.elm-lang.org/architecture/user_input/text_fields.html
I have problems with update and view :
-- UPDATE type Msg = Change String update : Msg -> Model -> Model update msg model = case msg of Change newContent -> { model | content = newContent } -- VIEW view : Model -> Html Msg view model = div [] [ input [ placeholder "Text to reverse", onInput Change ] [] , div [] [ text (String.reverse model.content) ] ]
Start with the Msg ad. The manual says:
It takes one argument, in this case the change function that was created when we declared the Msg type:
Edit: String -> Msg
I do not see how this happened here:
type Msg = Change String
How did we define the change function here? How did we determine how this function works? It seems to me that we just declared an Msg type, which somehow contains all the Change and the String type.
My second update question:
update : Msg -> Model -> Model update msg model = case msg of Change newContent -> { model | content = newContent }
It seems to me that the update is a higher order function that takes Msg and returns a Model -> Model function. But then we define a function with two parameters. Msg -> Model -> Model means that all but the last are parameters?
Then we call the Change function:
Change newContent -> { model | content = newContent }
What I canβt do is have an arrow. Usually an arrow appears after a parameter has been defined. But here we have the result of the function before -> .
I hope that my questions will make sense, I'm just very confused by this (supposedly amazing) language.
syntax elm
Moesattler
source share