Elm 0.17 简单 Mouse.clicks 示例
Elm 0.17 Simple Mouse.clicks example
为了熟悉 0.17 中的 subscriptions
,我试图让一个简单的应用程序运行,订阅 Mouse.clicks 并将 Model
递增一个。
目前该应用有以下投诉。
函数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)
问题出在您的 subscriptions
函数中。您需要这样设置:
subscriptions model =
Mouse.clicks (\_ -> Click)
为了熟悉 0.17 中的 subscriptions
,我试图让一个简单的应用程序运行,订阅 Mouse.clicks 并将 Model
递增一个。
目前该应用有以下投诉。
函数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)
问题出在您的 subscriptions
函数中。您需要这样设置:
subscriptions model =
Mouse.clicks (\_ -> Click)