खोज…


टिप्पणियों

अंशदान सुनने के साधन हैं। इनकमिंग पोर्ट , कीबोर्ड या माउस इवेंट, वेबसॉफ्ट मैसेज, जियोलोकेशन और पेज विजिबिलिटी में बदलाव, सभी इनपुट के रूप में काम कर सकते हैं।

'सदस्यता समाप्त' के साथ Time.every घटना के लिए बुनियादी सदस्यता

0.18.0

मॉडल सदस्यता के लिए पारित किया जाता है जिसका अर्थ है कि प्रत्येक राज्य परिवर्तन सदस्यता को संशोधित कर सकता है।

import Html exposing ( Html, div, text, button )
import Html.Events exposing ( onClick )
import Time

main : Program Never Model Msg
main =
    Html.program
        { init = init
        , update = update
        , subscriptions = subscriptions
        , view = view
        }

-- MODEL

type alias Model =
    { time: Time.Time
    , suspended: Bool
    }

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

-- UPDATE

type Msg
    = Tick Time.Time
    | SuspendToggle

update : Msg -> Model -> ( Model, Cmd Msg )
update msg model =
    case msg of
        Tick newTime ->
            ( { model | time = newTime }, Cmd.none )

        SuspendToggle ->
            ( { model | suspended = not model.suspended }, Cmd.none )

-- SUBSCRIPTIONS

subscriptions : Model -> Sub Msg
subscriptions model =
    if model.suspended then
        Sub.none
    else
        Time.every Time.second Tick

-- VIEW

view : Model -> Html Msg
view model =
    div []
        [ div [] [ text <| toString model ]
        , button [ onClick SuspendToggle ] [ text ( if model.suspended then "Resume" else "Suspend" ) ]
        ]


Modified text is an extract of the original Stack Overflow Documentation
के तहत लाइसेंस प्राप्त है CC BY-SA 3.0
से संबद्ध नहीं है Stack Overflow