Events should be delivered in order of firing
Closed this issue · 1 comments
zyla commented
We should respect the following property: When an event is fired with value X and then with value Y, each listener will see X first and Y second.
This is currently not the case. Consider the following example:
it "events are delivered in order of firing" do
{event,fire} <- liftEffect newEvent
log <- liftEffect $ newRef []
_ <- liftEffect $ execCleanupT $ flip subscribeEvent_ event \x ->
when (x == "first") $
fire "second"
_ <- liftEffect $ execCleanupT $ subscribeEvent_ (append log) event
liftEffect $ fire "first"
log `shouldHaveValue` ["first", "second"]
This test fails. The logging listener observes the following order: ["second", "first"]
.
That's due to #10 .
The property is essential for Dynamic to be useful. Consider a Dynamic listener that updates content on screen. In a series of events, the last value received by that listener will stay visible. If this is not the final value, we'll end up displaying stale data!
zyla commented
Added failing test case at https://github.com/restaumatic/purescript-specular/tree/feature/events-delivered-in-order