在使用elm reactor时是否有可能显示Elm的调试器?

9

在使用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
        }

你的应用程序是什么样子的?我从文档中输入了介绍应用程序,当使用反应器运行时,在浏览器的右下角看到“探索历史记录”选项。当有事件/更新时,可以前后回滚。你使用的 Elm 版本是哪个?似乎我仍在运行 0.18.0... - kaskelotti
@kaskelotti,我使用的是Elm 0.19版本,并且已经在问题中添加了一个示例。 - Robert K. Bell
在0.18.0版本中,主函数使用了Html包中的程序。在0.19.0版本中,有一个单独的Browser包,其中包含沙盒、应用程序等,似乎已经重新实现了...不幸的是,我的知识到此为止。 - kaskelotti
2个回答

9

在0.19版本中,elm reactor不再包含调试器。它似乎是在重构时被删除的(尽管将来可能会重新添加)。

现在,我建议使用elm-live,它也支持自动重新加载。


6

是的,现在没有elm reactor --debug了。但是您仍然可以在常规的elm make命令中找到--debug选项。因此,如果您的文件路径为src/Main.elm,则现在应该这样操作:

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

    Main ───> index.html

index.html 是通过设置 --debug 标志生成的。从 elm 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!

很希望在elm reactor中使用,但你仍然有一个index.html文件,可以在浏览器中“打开”。我用双引号括起来是因为如果你点击它打开,你看到的不是你想要看到的。你需要通过在终端上“服务”它,然后在浏览器上打开它的链接,就像你用elm reactor一样。现在大多数系统都安装了某个版本的Python,所以你可以使用Python命令来“服务”那个index.html文件,命令如下:
$ python3 -m http.server 8000

如果你只有Python 2.x版本,那么该命令应该是:

$ python –m SimpleHTTPServer 8000

当然,您可以按照任何其他方式提供服务。 您也可以使用elm reactorindex.html提供服务。 在elm reactor打开的主窗口中,找到生成的index.html的链接,并单击它,而不是src/Main.elm。 不过,我建议您不要使用此选项,因为它有可能会令人困惑。 现在,您可能不确定自己是否正在查看主要的src/Main.elm文件还是生成的index.html
至于elm-live,是的,这是一个很好的选择,您可以将--debug选项作为elm make选项提供。
$ elm-live src/Main.elm -- --debug

请注意--debug选项前面的--,因为它标志着elm-liveelm make options的开始。
如果没有其他问题,希望这样可以澄清如何找到和使用--debug。干杯。 (Elm 0.19.1)

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接