🗡️
ConanJs
  • What is ConanJs?
  • Why ConanJs...
    • ... if coming from Redux
    • ... if using vanilla React
    • ... if learning React
    • ... if not using React
  • How to install/use ConanJs
  • About us / Github / Contact us
  • Demos
    • Demo Gallery
    • Conan State Demos
      • Hello World
      • Todos
        • Todos - Basic
        • Todos - Async
        • Todos - Optimistic
      • Github issues viewer
    • Conan Flow Demos
      • Authentication
  • CONAN DATA
    • General Concepts
    • Conan State
      • Actions & Reducers
        • Reducers
        • Actions
      • Creating State
      • Observing State
        • Live rendering
        • Connecting
      • Composing State
      • Scaling State
      • Orchestrating State
      • Life cycle
        • Async handling
        • Introspection
      • Testing state
    • Conan Flow
      • Creating Flows
      • Serialising Flows
      • Observing Flows
  • CONAN Runtime
  • Dependency Injection
    • General Concepts
    • Creating the Context
    • Using the Context
  • ASAPs
  • Logging
  • API
    • Main Classes
      • Conan
        • StateDef
      • ConanState
      • ConanFlow
        • UserFlowDef
        • UserStatusDef
        • Status
    • Conan State Classes
      • Thread
      • ConnectedState
      • MonitorInfo
      • MetaInfo
    • Dependency Injection
      • DiContextFactory
    • ASAPS
      • Asaps
      • Asap
Powered by GitBook
On this page
  • Introduction
  • Threads and Flows
  • Threads
  • Flows
  • The Main Thread
  • The Monitor Thread
  • The Meta Flow
  • Accessing the Monitor Thread and the Meta Flow
  • Accessing only one state at a time

Was this helpful?

  1. CONAN DATA
  2. Conan State

Life cycle

PreviousOrchestrating StateNextAsync handling

Last updated 4 years ago

Was this helpful?

Introduction

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

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

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

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 Meta Flow

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

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

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.

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

Monitor async operations
Provide with introspection
action
Conan Flows
MonitorInfo
async handling
MetaInfo
Introspection
Monitor Info
ConanFlow
subscribe to
Async handling
Introspection
combination of data / monitor info / meta info.
Recursion!