noredink-ui/styleguide-app/Update.elm

48 lines
1.2 KiB
Elm
Raw Normal View History

2018-02-13 00:32:38 +03:00
module Update exposing (Msg(..), subscriptions, update)
2018-12-05 21:56:04 +03:00
import Browser exposing (UrlRequest(..))
2018-12-08 01:10:34 +03:00
import Browser.Navigation
2018-02-13 00:32:38 +03:00
import Model exposing (..)
import NriModules as NriModules
2018-12-05 21:56:04 +03:00
import Routes
import Url exposing (Url)
2018-02-13 00:32:38 +03:00
type Msg
= UpdateModuleStates NriModules.Msg
| OnUrlRequest Browser.UrlRequest
| OnUrlChange Url
2018-02-13 00:32:38 +03:00
| NoOp
update : Msg -> Model -> ( Model, Cmd Msg )
update action model =
case action of
UpdateModuleStates msg ->
let
( moduleStates, cmd ) =
NriModules.update msg model.moduleStates
in
( { model | moduleStates = moduleStates }
, Cmd.map UpdateModuleStates cmd
)
OnUrlRequest request ->
2018-12-05 21:56:04 +03:00
case request of
Internal loc ->
2018-12-08 01:10:34 +03:00
( model, Browser.Navigation.pushUrl model.navigationKey (Url.toString loc) )
2018-12-05 21:56:04 +03:00
External loc ->
2018-12-08 01:10:34 +03:00
( model, Browser.Navigation.load loc )
OnUrlChange route ->
2018-12-08 01:10:34 +03:00
( { model | route = Routes.fromLocation route }, Cmd.none )
2018-02-13 00:32:38 +03:00
NoOp ->
( model, Cmd.none )
subscriptions : Model -> Sub Msg
subscriptions model =
Sub.map UpdateModuleStates (NriModules.subscriptions model.moduleStates)