Skip to content

Knowing when "an epoch" has finished #114

@mike-thompson-day8

Description

@mike-thompson-day8

To implement many of the more advanced features we contemplate, we'll need a way of knowing when a re-frame Epoch has finished. So, how can we detect this?

A re-frame Epoch starts when an event is dispatched, and it continues until all consequent computations have ceased - all subscriptions and re-renders have run - and the application is quiescent.

A lot of these computations happen via use of future animation frames, so it can be hard to know when they are all done.

Current idea: is this the test we should use? (false? (.-scheduled? reagent.impl.batching/render-queue))

I believe that all subscriptions and re-renders happen via that queue. And if that queue is not scheduled to run in the future, then there's no further computation to be done and the Epoch is over. This idea needs to be tested - have I missed anything?

Obviously, reaching that far into Reagent's implementation is an ugly hack of biblical proportions but, if we can prove the concept is sound, I'll see about a PR to Reagent so that access becomes part of its future API.

Everytime we get trace arriving we know that something has happened. That's our call to attention. At that point we schedule a check in 16ms to see if the test given above is true. If it is, then we know that whatever caused the trace is now completed rippling through the application and we can do what we need to do at the end of an Epoch. (Obviously we'll get lots of trace, giving lots of calls-to-attention, so we'll have to debounce the resulting Epoch-has-ended test).

Note

  • An Epoch gets a bit messy (never ends) if activity (like rendering) happens for non-event-triggered reasons, like on-mouseover animations etc. Suddenly out of nowhere we'll get more trace well after we thought the Epoch had finished. In which case, I guess we simply have a new end to the Epoch. Epochs can have multiple ends.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions