deadghost
deadghost

Reputation: 5227

Suppress re-frame re-render

Is it possible to suppress a re-render? Suppose I dispatch handler [:a] and handler [:b] on state db-0. Such that:

db-0 -> [:a] -> db-1 -> [:b] -> db-0

The end state is the same but two re-renders are made. I do not wish for a re-render of the intermediary state db-1. A re-render, if necessary, should only happen after both [:a] and [:b] have both been applied.

Upvotes: 1

Views: 265

Answers (1)

Mike Thompson
Mike Thompson

Reputation: 976

Background

If a dispatch causes a change to app-db, an animation frame will be "scheduled" to handle any necessary re-rendering. As a result, that re-rendering will occur about 16ms later.

If, in the meantime, another dispatch happens, then its changes to app-db will also be handled in the already-scheduled, upcoming animation frame.

By the time the AF rolls around, the changes for both dispatched events will be manifest in app-db.

Your Scenario

So, as you can see, the dispatch of [:a] will cause an AF to be scheduled, however before it is run, your dispatch of [:b] will further change app-db back to its original state.

When later the AF runs, all the layer 2 subscriptions will run, all of them, because app-db was changed (in some way as yet unknown) BUT because previous values will = new values, the signal graph propagation will be pruned, and no re-renders will ultimately run.

Upvotes: 1

Related Questions