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)
非常感謝。發現! –