使用榆木反应堆时是否可以显示榆木的调试器?

Rob*_*ell 4 debugging elm

使用时elm reactor,它的效果很好,但似乎没有提供一种显示调试器的方法,以便在每次更新后显式查看模型的状态。

elm reactor --debug不起作用,我在UI中看不到选项,也没有在文档中看到它。

使用时可以看到调试器elm reactor吗?


这是在Reactor中运行但未显示调试器的代码示例(使用Elm 0.19时)

module Main exposing (main)

import Browser
import Html exposing (Html, button, div, text)
import Html.Events exposing (onClick)


type alias Model =
    { count : Int }


initialModel : Model
initialModel =
    { count = 0 }


type Msg
    = Increment
    | Decrement


update : Msg -> Model -> Model
update msg model =
    case msg of
        Increment ->
            { model | count = model.count + 1 }

        Decrement ->
            { model | count = model.count - 1 }


view : Model -> Html Msg
view model =
    div []
        [ button [ onClick Increment ] [ text "+1" ]
        , div [] [ text <| String.fromInt model.count ]
        , button [ onClick Decrement ] [ text "-1" ]
        ]


main : Program () Model Msg
main =
    Browser.sandbox
        { init = initialModel
        , view = view
        , update = update
        }
Run Code Online (Sandbox Code Playgroud)

Sid*_*ney 5

elm reactor0.19中不再包含调试器。显然在重构时已将其删除(尽管将来可能会对其进行重新添加)。

就目前而言,我建议您使用还支持自动重新加载的elm-live


sri*_*sri 5

是的,已经没有elm reactor --debug了。但是,您仍然会--debug在常规elm make. 所以如果你的文件是src/Main.elm你现在要做的:

$ elm make src/Main.html --debug
Success!

    Main ???> index.html
Run Code Online (Sandbox Code Playgroud)

index.html是在--debug设置标志的情况下生成的。Fromelm make的帮助,这意味着

--debug
    Turn on the time-travelling debugger. It allows you to rewind and replay
    events. The events can be imported/exported into a file, which makes for
    very precise bug reports!
Run Code Online (Sandbox Code Playgroud)

因此,拥有它会非常好,elm reactor但您仍然index.html可以在浏览器中“打开”它。我将 open 放在双引号中,因为如果您通过单击打开它,您将看不到您期望看到的内容。您希望通过以下方式正确打开它 - 从终端“提供”它,然后在浏览器上打开它的链接,就像您使用elm reactor. 现在大多数系统都安装了某些版本的python,因此您可以使用python命令使用命令来“提供”该index.html文件

$ python3 -m http.server 8000
Run Code Online (Sandbox Code Playgroud)

如果您只有 python 2.x,那么该命令应该是:

$ python –m SimpleHTTPServer 8000
Run Code Online (Sandbox Code Playgroud)

当然,您可以随意以任何其他方式提供服务。你也可以elm reactor用来服务index.html。在elm reactor打开的主窗口中,找到生成的链接index.html并单击它,而不是src/Main.elm。不过我建议不要使用它,因为它有可能令人困惑。您现在可能不确定您是在查看主src/Main.elm文件还是生成的index.html.

至于elm-live,是的,这是一个不错的选择,您可以将该--debug选项作为elm make option 提供

$ elm-live src/Main.elm -- --debug
Run Code Online (Sandbox Code Playgroud)

留意的是--在之前--debug的选项中,因为它标志着开始elm-live榆树化妆选项

如果不出意外,希望能澄清在哪里可以找到和使用--debug。干杯。

(榆树 0.19.1)