Life cycle
Last updated
Was this helpful?
Last updated
Was this helpful?
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 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 , 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.
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 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 meta flow has the several statuses that are handy to provide with introspection.
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
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.
myState$.asyncState
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.
Note that flows are not exactly the same as , but they are very similar.
The monitor thread collects all the information around async operations, and models that information into objects.
Check the section for more information on how to use this thread.
It maps all the information into objects
Check the section for more information.
asyncState. Returns a ConanState representation of the 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 which in turn, it can also be decomposed to obtain different ConanState
You could :
Leverage the ability to subscribe not only to data but a