alexmingoia / purescript-pux

Build type-safe web apps with PureScript.
https://www.purescript-pux.org
Other
566 stars 76 forks source link

Event fires faster than state update #150

Open madnight opened 6 years ago

madnight commented 6 years ago

Example: lets say we have a counter that should count to 10 and every scroll event increases the counter by +1. If the counter state is greater or equal to 10, then our increase state handler does nothing. Now lets assume the counter state is at 9 and we scroll very fast, so that new scroll events get triggered and processed asyncronously (thats the important point), so that the event handler in foldp reads the old state value of 9 and increases it by one. Now we look at the counter and it shows 13, although we never expect it to be more than 10.

I'm not exactly sure if its possible to reproduce the problem with simple counters, the problem that i have is a ajax request plus list mappend, with too many requests and appends if i scroll too fast, but not so if i scroll slowly so that a new event reads the updated state.

How do i solve this problem?