我正在尝试将 Elm 0.18 升级到 0.19 并卡在最后一步,我不知道如何将 Elm 0.18 代码重写为 Elm 0.19。我遇到的一个问题是,作为mgold/elm-date-format": "1.5.0 <= v < 2.0.0项目依赖项之一的 package 尚未升级以支持 Elm 0.19,因此我决定将其替换为ryannhg/date-format。我还阅读了迁移文档Time并Date移至elm/time,但我不知道如何重写下面的代码。我对 Elm 一无所知,所以请放轻松,我的任务是在我的项目中将 Elm 从 0.18 升级到 0.19。不过,我正在努力学习它。
这是我现在拥有的代码,它在升级到 0.19 加上完整的堆栈跟踪后不起作用。我使用自动Elm 升级工具来升级 Elm
代码:
module Views.Note exposing (view)
import Data.Note.Author exposing (Author)
import Data.Note exposing (Note)
import Html exposing (Html, text, span, tr, td, p)
import Html.Attributes exposing (class)
import Date.Format exposing(format)
import Date
import Views.Note.Author
-- VIEW --
view : Note -> List Author -> Html msg
view note authors=
let
author = List.head (List.filter (hasAuthorId note.authorId) authors)
in
case Date.fromString(note.createdAt) of
Ok date ->
tr []
[ td [ class "stacked" ]
[ span [ class "date" ][ text (format "%m/%d/%Y %l:%M %P" date) ]
, Views.Note.Author.view author
, p [ class "text" ][ text note.text ]
]
]
Err _ -> text ""
hasAuthorId : Maybe Int -> Author -> Bool
hasAuthorId authorId author =
case authorId of
Just authorId ->
author.id == authorId
_ ->
False
Run Code Online (Sandbox Code Playgroud)
堆栈跟踪:
ERROR in ./app/javascript/Page/Notes.elm
Module build failed (from ./node_modules/elm-webpack-loader/index.js):
Error: Compiler process exited with error Compilation failed
-- UNKNOWN IMPORT -------------------------------- app/javascript/Views/Note.elm
The Views.Note module has a bad import:
import Date
I cannot find that module! Is there a typo in the module name?
The "source-directories" field of your elm.json tells me to only look in the
app/javascript directory, but it is not there. Maybe it is in a package that is
not installed yet?
at ChildProcess.<anonymous> (/home/jedrek/workspace/ironin/lease_management_system/node_modules/node-elm-compiler/dist/index.js:131:35)
at ChildProcess.emit (events.js:203:13)
at maybeClose (internal/child_process.js:1021:16)
at Socket.<anonymous> (internal/child_process.js:430:11)
at Socket.emit (events.js:203:13)
at Pipe.<anonymous> (net.js:588:12)
Run Code Online (Sandbox Code Playgroud)
日期和时间的基本类型现在是Posix. 这就是格式化程序功能所期望的。现在最直接的替换Date.fromString是在https://package.elm-lang.org/packages/rtfeldman/elm-iso8601-date-strings/latest/Iso8601 - 见toTime函数,
您需要处理结果而不是 Maybe ,并且编译包的总大小会增加,因为它使用解析库而不是使用 javascript 的本机数据解析器
| 归档时间: |
|
| 查看次数: |
651 次 |
| 最近记录: |