This module enables you to prepare more precise debugging information
than the Initialization module.
The information provided by this module is available only when you compile
your application with elm make --debug.
When you use the Initialization module, the information shown in the Elm
Debugger during the initializing phase is often surprisingly poor.
This is because all Msg values in that phase are model-transforming functions,
which the debugger can only display as <internals>.
By using this module, you can:
String descriptions to each model-transforming function returned by commandsinitializingModel values before and after the transformationInitialization ModuleChange import Initialization as Init
to import Initialization.Debuggable as Init.
Using the same alias saves time and effort.
Add two type parameters, initUpdateInfo and blockingReason, to type annotation of main function,
just after initializingModel parameter in this order.
Add Init.toDebuggableCmd "" (always Nothing)
before each Cmd value passed to Cmd.batch in your init function.
Add Init.toDebuggable "" (always Nothing)
before each model-transforming function in the Html value returned
from the initView function.
Fill in the empty string arguments ("") with descriptions as needed.
Replace any of the (always Nothing) functions with
({ old : initializingModel, new : initializingModel } -> updateInfo),
where updateInfo is any type you define.
Wrapping the value in Just is usually sufficient.
The code below demonstrates how to debug Posix time initialization.
import Html
import Initialization.Debuggable as Init
import Task
import Time
type InitUpdateInfo
= PosixTimeUpdated { old : Maybe Time.Posix, new : Maybe Time.Posix }
type Msg
= Tick Time.Posix
main : Init.Program () { mTimezone : Maybe Time.Zone, mPosixTime : Maybe Time.Posix } (Maybe InitUpdateInfo) String { timezone : Time.Zone, posixTime : Time.Posix } Msg
main =
Init.element
{ init =
\() ->
( { mTimezone = Nothing
, mPosixTime = Nothing
}
, Cmd.batch
[ Init.toDebuggableCmd ""
(always Nothing)
(Task.perform (\tz im -> { im | mTimezone = Just tz }) Time.here)
, Init.toDebuggableCmd "updating posix time"
(\{ old, new } -> Just (PosixTimeUpdated { old = old.mPosixTime, new = new.mPosixTime }))
(Task.perform (\pt im -> { im | mPosixTime = Just pt }) Time.now)
]
)
, initView =
\blockingReasons iModel -> Html.div [] (List.map Html.text blockingReasons |> List.intersperse (Html.br [] []))
, toRunning =
\{ mTimezone, mPosixTime } ->
Ok (\tz pt -> ( { timezone = tz, posixTime = pt }, Cmd.none ))
|> Init.accumulate
(Result.fromMaybe "No timezone" mTimezone)
|> Init.accumulate
(Result.fromMaybe "No posixTime" mPosixTime)
}
{ subscriptions =
\_ -> Time.every 1000 Tick
, update =
\msg model ->
case msg of
Tick pt ->
( { model | posixTime = pt }, Cmd.none )
, view =
\{ timezone, posixTime } ->
Html.text <|
String.fromInt (Time.toHour timezone posixTime)
++ " : "
++ String.fromInt (Time.toMinute timezone posixTime)
++ " : "
++ String.fromInt (Time.toSecond timezone posixTime)
}Msg type used internally to represent model-transforming steps during the initializing phase.
Converts Cmd (initializingModel -> initializingModel)
into Cmd (MsgWithInfo updateInfo blockingReason initializingModel).
This function is intended to be used in the init function.
Converts initializingModel -> initializingModel
into MsgWithInfo updateInfo blockingReason initializingModel.
This function is intended to be used in the initView function.
Similar to Initialization.element, but requires that all Msg values
are converted from initializingModel -> initializingModel
into MsgWithInfo initUpdateInfo blockingReason initializingModel
using toDebuggableCmd and toDebuggable.
Similar to Initialization.document, but requires that all Msg values
are converted from initializingModel -> initializingModel
into MsgWithInfo initUpdateInfo blockingReason initializingModel
using toDebuggableCmd and toDebuggable.
The same as Initialization.accumulate.
Type alias for
Platform.Program flag <internally defined Model type> <internally defined Msg type>.