gpt4 book ai didi

elm - 什么时候可以更改应用程序模型?

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

我想知道应用模型何时会发生变化。

具体来说,这样的代码是否保证正确?

onClick <| UpdateModelVersionMessage (model.version + 1)

也就是说,在呈现 UI 组件与注册和分派(dispatch)事件之间,是否可以通过其他方式更新模型,例如 UpdateModelVersionMessage值已过时? Javascript 的并发模型让我相信我是安全的。但是 Elm 正在做或者 Elm 可能会做一些像批处理/重新排序消息这样的事情吗?

最佳答案

我被告知,从 0.18 开始:

The view is rendered asynchronously through requestanimationframe so, no, it's not safe.

还有:

in 0.19, html events will trigger synchronous rerenders, so that will not be a problem

最后:

Requestanimationframe runs at 60fps, tho, so the window for events to be sent with an outdated model is really small
i.e. 16ms at most, assuming your view can render within a single frame (if it can't, that's a different issue)
So in this case, I'd recommend doing the simplest thing that could possibly work, knowing the odds of it going wrong are very very slim, and knowing that in 0.19, the view can re-render synchronously, preventing this from being an possible issue altogether

感谢 Ilias ( https://github.com/zwilias) 的回答。

关于elm - 什么时候可以更改应用程序模型?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46302134/

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