Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When can the app model change?

Tags:

elm

I'm wondering when the app model might change.

Specifically, is code like this guaranteed to be correct, or not?

onClick <| UpdateModelVersionMessage (model.version + 1)

That is, between rendering the UI component, and registering and dispatching the event, could something else update the model such that the UpdateModelVersionMessage value is out of date? Javascript's concurrency model makes me believe I'm safe. But is Elm doing or could Elm possibly do something like batching/reordering messages?

like image 729
Mark Bolusmjak Avatar asked Dec 02 '25 23:12

Mark Bolusmjak


1 Answers

I have been informed that, as of 0.18:

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

But also:

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

And finally:

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

Thanks to Ilias (https://github.com/zwilias) for the answers.

like image 158
Mark Bolusmjak Avatar answered Dec 08 '25 05:12

Mark Bolusmjak



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!