Life cycle


Each ConanJs state object has a a life cycle. This life cycle helps tracking several aspects of the State including:

To understand the life cycle we need to get some insight on what is inside a ConanState. It is composed of.

  • The Main Thread

  • The Monitor Thread (for async operations)

  • The Meta Flow (for introspection / error handling)

We also need to introduce the thread and flows

Threads and Flows

Threads and flows are the building blocks of ConanJs, while you don't need to have a deep understanding of them, it is helpful to have an overview.


Threads are streams of data that have the same shape.

When you update the state of the Conan State through an action, the main thread is notified and stores the new state, so it can be accessed.


Flows have statuses, each status then has, similar to the thread, a stream of data with the same shape.

A flow has a current status, and you can also transition to a different status.

Note that flows are not exactly the same as Conan Flows, but they are very similar.

Both threads and flow can be started or stopped

ConanJs auto-starts Conan State for you, so most of the times you don't have to worry about this.

Is a handy feature to have though for advanced use cases

The Main Thread

The main thread is where all the data updates are stored.

Most of the features of the Conan State affect this Thread, it is also not accessible directly to protect it from unintentional changes.

The Monitor Thread

The monitor thread collects all the information around async operations, and models that information into MonitorInfo objects.

Check the async handling section for more information on how to use this thread.

The Meta Flow

The meta flow has the several statuses that are handy to provide with introspection.

It maps all the information into MetaInfo objects

Check the Introspection section for more information.

Accessing the Monitor Thread and the Meta Flow

Each ConanState allows easy access to the information encapsulated in the monitor flow and the meta flow through.... (can you guess it?).... more ConanState!

There are two properties in the ConanState for this

  • asyncState. Returns a ConanState representation of the Monitor Info contained in the Monitor Thread. Since it returns a new ConanState, you can perform all the operations that you would with any other ConanState!

  • metaFlow. Returns a ConanFlow which in turn, it can also be decomposed to obtain different ConanState

Accessing only one state at a time

You could subscribe to the state produced by these properties as you would with any normal Conan State/ Conan Flow, this will work well if you want to consume in isolation the Meta info or the Monitor Info.

This could be the case when you have a loading overlay component where you are only interested in showing if some state is currently performing an asyncAction.

You could subscribe to:


Many times though you are probably going to be interested in combining the data with either the Meta info and/or the Monitor info.

In that case you have two options.

Do this yourself by composing a new state using the original ConanState and the results from the properties asyncState/metaFlow, and subscribe to this new state.

Leverage the ability to subscribe not only to data but a combination of data / monitor info / meta info.

Async handlingIntrospection

Last updated