elm

Elm Html.Events - Pass input value to onBlur message

僤鯓⒐⒋嵵緔 提交于 2019-12-04 11:33:45
I have this kind of input: inputName player = input [ type_ "text" , onInput (Msgs.ChangeName player) , value player ] which creates Msgs.ChangeName for every single character added to input. I would prefer to update model after user leaves input but onBlur doesn't have any payload about input: inputName player = input [ type_ "text" , onBlur (Msgs.ChangeName player) , value player ] Above code doesn't compile ending with error: The 1st entry has this type: Html (String -> Msg) But the 2nd is: Html (Msg) Hint: It looks like a function needs 1 more argument. You can create a variation on the

Does Functional Reactive Programming in JavaScript cause bigger problems with listener references?

夙愿已清 提交于 2019-12-04 10:05:40
问题 In JavaScript the observer pattern is used quite often. There is one tricky thing with it and that's the references the subject keeps of the observers. They require cleanup. For regular applications I use the following rules of thumb: If the subject has a life span shorter than (or equal to) the observer, I can just do subject.on('event', ...) If the subject has a life span longer than the observer, I need to use observer.listenTo(subject, 'event', ...) In the second case, the listenTo is

In Elm, is there a way to merge union types ? (for modularity purpose)

六月ゝ 毕业季﹏ 提交于 2019-12-04 08:27:35
Starting from those three declarations : type SharedMsg = SharedAction type Page1Msg = Page1Action type Page2Msg = Page2Action I there a way to obtain an equivalent of the following one? Like a way to "merge" union types ? type Msg = SharedAction | Page1Action | Page2Action ============================= Context : I am splitting an Elm application into one module per page with their own folders. Some actions will be shared, and some actions will be page-specific. If I was to use the Html.map method, I feel that I would have to re-write every shared action that a page uses in its own PageMsg

<~ in elm 0.16.0 gives me a compile time error

北城以北 提交于 2019-12-04 04:18:58
问题 Very new to Elm but wanted to play around with the <~ operator. It seems when I run elm-make, <~ it is not recognized as an operator, and I get the error Cannot find variable <~ Has this been deprecated ( I see it in the docs at elm-lang.org/docs/syntax#mapping ). Am I just using it incorrectly? Here is my code snippet that will not compile- sqrtSig : Signal number sqrtSig = sqrt <~ Mouse.x 回答1: Yes, <~ and ~ were removed following this discussion 来源: https://stackoverflow.com/questions

how to tell elm about external DOM changes

本秂侑毒 提交于 2019-12-04 04:00:47
问题 I'm using elm 0.17.1 and trying to interop with select2 javascript library(version 4.0.3), here is my Main.elm : port module Main exposing (..) import Html exposing (Html,select,option,div,text,br) import Html.App as App import Html.Attributes exposing (id,value,width) -- MODEL type alias Model = { country : String } -- UPDATE type Msg = Select String update : Msg -> Model -> (Model, Cmd Msg) update msg model = case msg of Select str -> (Model str,Cmd.none) -- VIEW view : Model -> Html Msg

how to update an inner record in elm

匆匆过客 提交于 2019-12-04 03:42:41
问题 I have this model type alias Model = { exampleId : Int , groupOfExamples : GroupExamples } type alias GroupExamples = { groupId : Int , results : List String } In my update function, if I want to update the exampleId would be like this: { model | exampleId = updatedValue } But what if I need to do to update, for example, just the results value inside of GroupExamples? 回答1: The only way to do it in the language without anything extra is to destructure the outer record like: let examples =

How do I add a second die to this elm effects example?

丶灬走出姿态 提交于 2019-12-03 22:51:55
I am new to Elm and have been looking at the following example (note this is under the newer 0.17 architecture, where Action is now Command): http://elm-lang.org/examples/random There is a follow up challenge to add a second die to the example, so that a single click of the button rolls a new value for each die. My idea is to change the model to hold two separate values, one for each die, ala type alias Model = { dieFace1 : Int , dieFace2 : Int } This works fine until I get to the update block. I am not sure how to update the Random number generator to create two values. The function is a bit

Work with elm and select

走远了吗. 提交于 2019-12-03 15:22:40
问题 I try to understand how elm works with a custom example. durationOption duration = option [value (toString duration) ] [ text (toString duration)] view : Model -> Html Msg view model = Html.div [] [ h2 [] [ text "Month selector"] , select [] (List.map durationOption [1..12]) ] It's an easy example to work with a select. I would like, each time I change the month value it multiplies to value by 10 for example. According to the documentation there is not events like onChange or onSelect , do I

Elm: How to decode data from JSON API

本小妞迷上赌 提交于 2019-12-03 12:08:38
问题 I have this data using http://jsonapi.org/ format: { "data": [ { "type": "prospect", "id": "1", "attributes": { "provider_user_id": "1", "provider": "facebook", "name": "Julia", "invitation_id": 25 } }, { "type": "prospect", "id": "2", "attributes": { "provider_user_id": "2", "provider": "facebook", "name": "Sam", "invitation_id": 23 } } ] } I have my models like: type alias Model = { id: Int, invitation: Int, name: String, provider: String, provider_user_id: Int } type alias Collection =

What is an opaque type in Elm and why is it valuable?

有些话、适合烂在心里 提交于 2019-12-03 11:50:44
问题 I've used types before but don't know what an opaque type is. I've seen it mentioned as well. Is it better to expose an opaque type than a type alias? 回答1: Let’s answer this question by first looking at type aliases: A type alias is fully transparent. This means that any other module importing it will have full access to its inner workings. Let’s say we’ve got a User module exposing a User type: module User exposing User type alias User = { userName : String , age : Int } Anyone importing