mirror of
https://github.com/dillonkearns/elm-pages-v3-beta.git
synced 2024-12-26 13:21:42 +03:00
Add Effect module to docs site.
This commit is contained in:
parent
979be6f3e4
commit
e6fb1047ec
51
examples/docs/app/Effect.elm
Normal file
51
examples/docs/app/Effect.elm
Normal file
@ -0,0 +1,51 @@
|
||||
module Effect exposing (Effect(..), batch, fromCmd, map, none, perform)
|
||||
|
||||
import Http
|
||||
import Json.Decode as Decode
|
||||
|
||||
|
||||
type Effect msg
|
||||
= None
|
||||
| Cmd (Cmd msg)
|
||||
| Batch (List (Effect msg))
|
||||
|
||||
|
||||
none : Effect msg
|
||||
none =
|
||||
None
|
||||
|
||||
|
||||
batch : List (Effect msg) -> Effect msg
|
||||
batch =
|
||||
Batch
|
||||
|
||||
|
||||
fromCmd : Cmd msg -> Effect msg
|
||||
fromCmd =
|
||||
Cmd
|
||||
|
||||
|
||||
map : (a -> b) -> Effect a -> Effect b
|
||||
map fn effect =
|
||||
case effect of
|
||||
None ->
|
||||
None
|
||||
|
||||
Cmd cmd ->
|
||||
Cmd (Cmd.map fn cmd)
|
||||
|
||||
Batch list ->
|
||||
Batch (List.map (map fn) list)
|
||||
|
||||
|
||||
perform : (pageMsg -> msg) -> Effect pageMsg -> Cmd msg
|
||||
perform fromPageMsg effect =
|
||||
case effect of
|
||||
None ->
|
||||
Cmd.none
|
||||
|
||||
Cmd cmd ->
|
||||
Cmd.map fromPageMsg cmd
|
||||
|
||||
Batch list ->
|
||||
Cmd.batch (List.map (perform fromPageMsg) list)
|
@ -3,6 +3,7 @@ module Shared exposing (Data, Model, Msg, template)
|
||||
import Browser.Navigation
|
||||
import DataSource
|
||||
import DocsSection
|
||||
import Effect exposing (Effect)
|
||||
import Html exposing (Html)
|
||||
import Html.Styled
|
||||
import Pages.Flags
|
||||
@ -60,27 +61,27 @@ init :
|
||||
, metadata : route
|
||||
, pageUrl : Maybe PageUrl
|
||||
}
|
||||
-> ( Model, Cmd Msg )
|
||||
-> ( Model, Effect Msg )
|
||||
init navigationKey flags maybePagePath =
|
||||
( { showMobileMenu = False
|
||||
, counter = 0
|
||||
, navigationKey = navigationKey
|
||||
}
|
||||
, Cmd.none
|
||||
, Effect.none
|
||||
)
|
||||
|
||||
|
||||
update : Msg -> Model -> ( Model, Cmd Msg )
|
||||
update : Msg -> Model -> ( Model, Effect Msg )
|
||||
update msg model =
|
||||
case msg of
|
||||
OnPageChange _ ->
|
||||
( { model | showMobileMenu = False }, Cmd.none )
|
||||
( { model | showMobileMenu = False }, Effect.none )
|
||||
|
||||
ToggleMobileMenu ->
|
||||
( { model | showMobileMenu = not model.showMobileMenu }, Cmd.none )
|
||||
( { model | showMobileMenu = not model.showMobileMenu }, Effect.none )
|
||||
|
||||
IncrementFromChild ->
|
||||
( { model | counter = model.counter + 1 }, Cmd.none )
|
||||
( { model | counter = model.counter + 1 }, Effect.none )
|
||||
|
||||
|
||||
subscriptions : Path -> Model -> Sub Msg
|
||||
|
Loading…
Reference in New Issue
Block a user