Elm:端口在嵌套模块中不起作用
Elm: Ports not working in nested modules
我正在尝试通过调整要嵌套的工作示例来使端口在嵌套模块中工作。在这种情况下 Save2.elm 调用 fileSelected,一个 JavaScript 函数。
但是,这不起作用。
调试显示消息 "Json Selected" 已触发。不幸的是,JavaScript 函数永远不会被调用。
Ports.elm中定义的端口:
port fileSelected : String -> Cmd msg
Save2.elm的相关部分,"Json Selected"部分被触发:
update : Msg -> Model -> ( Model, Cmd Msg )
update msg model =
case msg of
JsonSelected inputBoxId ->
( model
, fileSelected inputBoxId
)
相关JavaScript部分:
<script src="main.js"></script>
<script>
var app = Elm.Main.fullscreen();
// This log is shown from start-up
console.log("Upload.html console.log is shown")
app.ports.fileSelected.subscribe(function (id) {
// This log is never shown
console.log("fileSelected is executed")
A link 到回购:
https://github.com/gitLabor8/Elm-Ports-not-working-in-nested-modules
提前致谢,
在您的代码库中,Save2.update
中的 Cmd
在 Main.update
中被忽略了。
update : Msg -> Model -> ( Model, Cmd Msg )
update msg model =
case msg of
Save2 saveMsg ->
( { model | save2 = Tuple.first (Save2.update saveMsg model.save2) }
, Cmd.none
)
您需要从 Main.update
return 它以便 Elm 运行时可以处理 Cmd
。
update : Msg -> Model -> ( Model, Cmd Msg )
update msg model =
case msg of
Save2 saveMsg ->
let
( save2Model, save2Cmd )
= Save2.update saveMsg model.save2
in
( { model | save2 = save2Model }
, save2Cmd
)
在 Elm 中,调用 port
函数不会触发任何东西。它们只是必须由 Elm 运行时处理的 return Cmd
s。
我正在尝试通过调整要嵌套的工作示例来使端口在嵌套模块中工作。在这种情况下 Save2.elm 调用 fileSelected,一个 JavaScript 函数。 但是,这不起作用。
调试显示消息 "Json Selected" 已触发。不幸的是,JavaScript 函数永远不会被调用。 Ports.elm中定义的端口:
port fileSelected : String -> Cmd msg
Save2.elm的相关部分,"Json Selected"部分被触发:
update : Msg -> Model -> ( Model, Cmd Msg )
update msg model =
case msg of
JsonSelected inputBoxId ->
( model
, fileSelected inputBoxId
)
相关JavaScript部分:
<script src="main.js"></script>
<script>
var app = Elm.Main.fullscreen();
// This log is shown from start-up
console.log("Upload.html console.log is shown")
app.ports.fileSelected.subscribe(function (id) {
// This log is never shown
console.log("fileSelected is executed")
A link 到回购: https://github.com/gitLabor8/Elm-Ports-not-working-in-nested-modules
提前致谢,
在您的代码库中,Save2.update
中的 Cmd
在 Main.update
中被忽略了。
update : Msg -> Model -> ( Model, Cmd Msg )
update msg model =
case msg of
Save2 saveMsg ->
( { model | save2 = Tuple.first (Save2.update saveMsg model.save2) }
, Cmd.none
)
您需要从 Main.update
return 它以便 Elm 运行时可以处理 Cmd
。
update : Msg -> Model -> ( Model, Cmd Msg )
update msg model =
case msg of
Save2 saveMsg ->
let
( save2Model, save2Cmd )
= Save2.update saveMsg model.save2
in
( { model | save2 = save2Model }
, save2Cmd
)
在 Elm 中,调用 port
函数不会触发任何东西。它们只是必须由 Elm 运行时处理的 return Cmd
s。