Skip to content
aldonline edited this page Oct 13, 2014 · 6 revisions

The radioactive.react() loop is Radioactive's workhorse. You will find yourself creating tons of loops. And, in some cases, loops within loops.

How does the loop work?

In its most basic form, a loop runs from top to bottom. It will then wait for a change notification. At that moment, it will run again.

Sometimes, however, a loop will stop at an intermediate point. Before reaching the end of the block of code. This will happen whenever Radioactive is waiting from data to arrive from an async datasource.

Partial Executions

Lifecycle

You may be wondering whether keeping all these loops alive is expensive. The answer is: it depends.

  1. Any normal application should not need more than a few hundred of these loops to be alive at any given point in time.
  2. The problem is that is is sometimes hard to keep track of when they are created, and when they are destroyed

As someone once said:

Premature optimization is the root of all Evil. - Donald Knuth

But if you do need to optimize, then it is useful to understand what's going on.

The loop hierarchy

Loops are implicitly created in a hierarchy. If you create a loop from a block of code that is executing within another loop, then the outer loop will automatically become the inner loop's parent.

This hierarchy, along with some assumptions and heuristics, give us a simple way of limiting the lifespan of a loop.

Detached loops

DOM Lifecycle bound Loops

Clone this wiki locally