수색…


소개

ccapndave / elm-update-extra는보다 복잡한 업데이트 기능을 다루는 데 도움이되고 매우 유용 할 수있는 환상적인 패키지입니다.

메시지 목록을 호출하는 메시지

sequence 기능을 사용하면 다른 메시지 목록을 호출하는 메시지를 쉽게 설명 할 수 있습니다. 메시지의 의미를 다룰 때 유용합니다.

예제 1 : 게임 엔진을 만들고 있고 모든 프레임에서 화면을 새로 고침해야합니다.

module Video exposing (..)
type Message = module Video exposing (..)

import Update.Extra exposing (sequence)

-- Model definition [...]

type Message
    = ClearBuffer
    | DrawToBuffer
    | UpdateLogic
    | Update

update : Message -> Model -> (Model, Cmd)
update msg model =
    case msg of
        ClearBuffer ->
            -- do something
        DrawToBuffer ->
            -- do something
        UpdateLogic ->
            -- do something
        Update ->
            model ! []
                |> sequence update [ ClearBuffer
                                   , DrawToBuffer
                                   , UpdateLogic]

and와의 메시지 묶기

andThen 함수는 업데이트 호출 구성을 허용합니다. 파이프 라인 운영자 ( |> )와 함께 체인 업데이트에 사용할 수 있습니다.

예 : 문서 편집기를 만들고 있으며, 문서에 보내는 각 수정 메시지를 저장하려면 다음과 같이하십시오.

import Update.Extra exposing (andThen)
import Update.Extra.Infix exposing (..)

-- type alias Model = [...]

type Message
    = ModifyDocumentWithSomeSettings
    | ModifyDocumentWithOtherSettings
    | SaveDocument

update : Model -> Message -> (Model, Cmd)
update model msg =
    case msg of
        ModifyDocumentWithSomeSettings ->
            -- make the modifications
            (modifiedModel, Cmd.none)
            |> andThen SaveDocument
        ModifyDocumentWithOtherSettings ->
            -- make other modifications
            (modifiedModel, Cmd.none)
            |> andThen SaveDocument
        SaveDocument ->
            -- save document code

Update.Extra.Infix exposing (..) 을 가져 Update.Extra.Infix exposing (..) 삽입 연산자를 사용할 수 있습니다.

update : Model -> Message -> (Model, Cmd)
update model msg =
    case msg of
        ModifyDocumentWithSomeSettings ->
            -- make the modifications
            (modifiedModel, Cmd.none)
            :> andThen SaveDocument
        ModifyDocumentWithOtherSettings ->
            -- make other modifications
            (modifiedModel, Cmd.none)
            :> SaveDocument
        SaveDocument ->
            -- save document code


Modified text is an extract of the original Stack Overflow Documentation
아래 라이선스 CC BY-SA 3.0
와 제휴하지 않음 Stack Overflow