gpt4 book ai didi

elm - 当 Elm Html.Program 调用订阅时

转载 作者:行者123 更新时间:2023-12-04 02:04:24 25 4
gpt4 key购买 nike

我在 a Google Group 中找到了这个问题的可能答案但我想知道它是否正确,如果正确则添加一个后续问题。

答案就在这里

Every time the global update function in your app runs for any reason, the global subscriptions object is reevaluated as well, and effect managers receive the new list of current subscriptions

如果任何时候模型发生变化,subscriptions 都会被调用,这对订阅有什么影响,例如 Time.every second 取自 Time Effect Elm Guide - 这是否意味着模型更改时计时器会重置?如果那是 Time.every minute - 如果模型在启动后 20 秒发生变化,它会在 60 - 20 = 40 秒 后触发还是会在 后触发1 分钟?

最佳答案

您可以检查 updatesubscriptions 何时被调用,方法是为每个调用添加一个 Debug.log 语句。 subscriptions 函数在开始时首先被调用(因为将发送到 update 的消息可能取决于它),并且在每次调用 update .

计时器间隔似乎不受后续调用 subscriptions 的影响。例如,如果您使用 elm clock example , 将订阅更改为

Time.every (10*Time.second) Tick

并在 View 中添加一个将模型值重置为 0 的按钮,无论您何时单击该按钮,您都会看到滴答仍然以 10 秒的固定间隔发生。

关于elm - 当 Elm Html.Program 调用订阅时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44609208/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com