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
|
2018-12-05 01:36:15 +03:00
|
|
|
import Url exposing (Url)
|
2018-02-13 00:32:38 +03:00
|
|
|
|
|
|
|
|
|
|
|
type Msg
|
|
|
|
= UpdateModuleStates NriModules.Msg
|
2018-12-05 01:36:15 +03:00
|
|
|
| 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
|
|
|
|
)
|
|
|
|
|
2018-12-05 01:36:15 +03:00
|
|
|
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 )
|
2018-12-05 01:36:15 +03:00
|
|
|
|
|
|
|
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)
|