2016-05-17 63 views
1

要熟悉subscriptions in 0.17我試圖獲得一個簡單的應用程序,訂閱Mouse.clicks並將Model加1。榆樹0.17 Simple Mouse.clicks示例

目前該應用程序有以下投訴。

功能program期待的說法是:

{ ... 
    , subscriptions : Float -> Sub Msg 
    , update : Msg -> Float -> (Float, Cmd Msg) 
    , view : Float -> Html Msg 
} 

但它是:

{ ... 
    , subscriptions : (Msg -> Position -> a) -> Sub a 
    , update : Msg -> number -> (number, Cmd b) 
    , view : c -> Html d 
} 

任何幫助,這將非常感激。

import Html exposing (Html, text, div) 
import Html.App as Html 
import Mouse exposing (..) 

main = 
    Html.program 
    { init = init 
    , view = view 
    , update = update 
    , subscriptions = subscriptions 
    } 

-- MODEL 

type alias Model = Int 

init : (Model, Cmd Msg) 
init = 
    (0, Cmd.none) 

-- UPDATE 

type Msg 
    = Click 

update msg model = 
    case msg of 
    Click -> 
     (model + 1 , Cmd.none) 

-- SUBSCRIPTIONS 

subscriptions model = 
    Mouse.clicks (model Click) 

-- VIEW 

view model = 
    Html.text (toString model) 

回答

1

問題在於你的subscriptions函數。你需要像這樣設置它:

subscriptions model = 
    Mouse.clicks (\_ -> Click) 
+0

非常感謝。發現! –