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

When can the app model change?

我想知道应用程序模型何时会更改。

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

onClick <| UpdateModelVersionMessage (model.version + 1)

也就是说,在呈现 UI 组件与注册和分派事件之间,是否可以通过其他方式更新模型,使 UpdateModelVersionMessage 值过时? Javascript 的并发模型让我相信我是安全的。但是 Elm 正在做或者 Elm 可能会做类似 batching/reordering 消息的事情吗?

我被告知,从 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) 的回答。