Elm语言Outgoing
示例
出站端口用作命令,从update功能中返回。
榆木边
定义输出端口:
port output : () -> Cmd msg
在此示例中,我们发送了一个空的Tuple,只是为了触发JavaScript端的订阅。
为此,我们必须应用output带有空Tuple作为参数的函数,以获得从Elm发送输出数据的命令。
update msg model =
case msg of
TriggerOutgoing data ->
( model, output () )JavaScript方面
初始化应用程序:
var root = document.body; var app = Elm.Main.embed(root);
订阅具有相应名称的端口:
app.ports.output.subscribe(function () {
alert('Outgoing message from Elm!');
});注意
截至0.17.0,从您的initial状态到JavaScript的立即传出消息将无效。
init : ( Model, Cmd Msg )
init =
( Model 0, output () ) -- Nothing will happen请参阅下面的示例中的解决方法。
热门推荐
10 天气转凉祝福语简短
11 公司28 周年祝福语简短
12 生日贺卡祝福语 简短独特
13 茶人生日祝福语简短
14 喜事敬酒祝福语简短精辟
15 蛋糕祝老师祝福语简短
16 50多岁生日简短祝福语
17 生日祝福语贺卡文字简短
18 38节贺卡简短祝福语