# ConanState

The class ConanState contains the following methods:

### ***connectMap \<PROPS>***

this method allows connecting a Conan state with a React component, using a mapper function to describe the mapping

| Input     |                                                                                                                                                                                                              |
| --------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| toConnect | <p><strong>Type:</strong>  <code>React.ComponentType </code><em><code>required</code></em></p><p>the component type we want to connect</p>                                                                   |
| mapper    | <p><strong>Type:</strong>  <code>IBiFunction\<DATA, ACTIONS, PROPS> </code><em><code>required</code></em></p><p> A function that receives DATA and ACTIONS. It describes how the PROPS will be connected</p> |

| Returns      |                           |
| ------------ | ------------------------- |
| ReactElement | A connected React element |

### ***connectData***

this method allows connecting all Conan state data with a React component,

| Input     |                                                                                                                                            |
| --------- | ------------------------------------------------------------------------------------------------------------------------------------------ |
| toConnect | <p><strong>Type:</strong>  <code>React.ComponentType </code><em><code>required</code></em></p><p>the component type we want to connect</p> |

| Returns      |                           |
| ------------ | ------------------------- |
| ReactElement | A connected React element |

### ***connect***

‌this method allows connecting all Conan state  with a React component

| Input     | ​Title                                                                                                                                                                     |
| --------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| toConnect | <p><strong>Type:</strong> <code>React.ComponentType\<ConnectedState\<DATA, ACTIONS>> </code><em><code>required</code></em></p><p>the component type we want to connect</p> |

| Returns                       | ​Title                                        |
| ----------------------------- | --------------------------------------------- |
| ReactElement\<ConnectedState> | A React element with the whole ConnectedState |

### ***connectLive***

‌this method allows producing connected react elements by accepting a renderer function, which receives the ConanState data and actions.

| Input         | ​Title                                                                                                   |                                                                                                                                     |
| ------------- | -------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------- |
| renderer      | <p><strong>Type:</strong> <code>IBiFunction\<DATA, ACTIONS, ReactElement                                 | ReactElement\[]> </code><em><code>required</code></em></p><p>The render function that will produce out connected react elements</p> |
| fallbackValue | <p><strong>Type:</strong> DATA optional</p><p>default DATA in case nothing is there when initialised</p> |                                                                                                                                     |

| Returns      | ​Title                          |
| ------------ | ------------------------------- |
| ReactElement | A State connected React element |

### ***addDataReaction***

‌this method can be uses to add a custom data reaction a un ConanState

| Input | ​Title                                                                                                                                     |
| ----- | ------------------------------------------------------------------------------------------------------------------------------------------ |
| def   | <p><strong>Type:</strong> <code>DataReactionDef\<DATA> </code><em><code>required</code></em></p><p>the custom data reaction definition</p> |

| Returns          | ​Title                        |
| ---------------- | ----------------------------- |
| DataReactionLock | TBC: Alberto que coño es esto |

### ***do***

‌this method returns the actions available for this ConanState

| Input | ​Title |
| ----- | ------ |
| void  |        |

| Returns          | ​Title                                |
| ---------------- | ------------------------------------- |
| DataReactionLock | actions available for this ConanState |

### *getData*

‌this method returns the current data of this ConanState

| Input | ​Title |
| ----- | ------ |
| void  |        |

| Returns | ​Title                          |
| ------- | ------------------------------- |
| DATA    | current data of this ConanState |

### *filter*

‌this method returns a filtered ConanState

| Input  | ​Title                                                                                                                                                                                                                              |
| ------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| mapper | <p><strong>Type:</strong> <code>(current: DATA, previous: DATA) => boolean </code><em><code>required</code></em></p><p><code>the filter function that receives the current and previous DATA and has to return a boolean</code></p> |

| Returns           | ​Title                            |
| ----------------- | --------------------------------- |
| ConanState\<DATA> | The resulting filtered ConanState |

### *map\<T>*

‌this method returns a remapped ConanState

| Input  | ​Title                                                                                                                                                                                                             |
| ------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| mapper | <p><strong>Type:</strong> <code>IFunction\<DATA, T> </code><em><code>required</code></em></p><p><code>the mapper function that receives the current DATA and has to return the new remmapped ConanState</code></p> |

| Returns           | ​Title                            |
| ----------------- | --------------------------------- |
| ConanState\<DATA> | The resulting remapped ConanState |

### *merge\<T, TO\_MERGE>*

‌this method returns a remapped ConanState

| Input    | ​Title                                                                                                                                                                            |
| -------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| toMerge$ | <p><strong>Type:</strong> <code>ConanState\<TO\_MERGE, any> </code><em><code>required</code></em></p><p><code>the ConanState that we want to merge with</code></p>                |
| merger   | <p><strong>Type:</strong> <code>ITriFunction\<DATA, TO\_MERGE, T, T> </code><em><code>required</code></em></p><p><code>the function that describes the merge operation</code></p> |

| Returns        | ​Title                          |
| -------------- | ------------------------------- |
| ConanState\<T> | The resulting merged ConanState |

### *tuple\<TO\_MERGE>*

‌this method combined two states into one

| Input    | ​Title                                                                                                                                                             |
| -------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| toMerge$ | <p><strong>Type:</strong> <code>ConanState\<TO\_MERGE, any> </code><em><code>required</code></em></p><p><code>the ConanState that we want to merge with</code></p> |

| Returns                        | ​Title                            |
| ------------------------------ | --------------------------------- |
| ConanState<\[DATA, TO\_MERGE]> | The resulting combined ConanState |

### *asyncState*

‌this method gives access to the async state data and actions

| Input | ​Title |
| ----- | ------ |
| void  |        |

| Returns                                  | ​Title                           |
| ---------------------------------------- | -------------------------------- |
| ConanState\<MonitorInfo, MonitorActions> | the async state data and actions |

### *metaFlow* <a href="#asyncstate" id="asyncstate"></a>

‌‌this method gives access to the state meta flow

| Input | ​Title       |
| ----- | ------------ |
| void  | **​**Content |

| Returns                                | ​Title                             |
| -------------------------------------- | ---------------------------------- |
| ConanFlow\<MetaStatuses, MetaMutators> | the meta Conan flow for this state |

### *combine\<T extends {}, ACTIONS = void>*

‌this method combined two states into one

| Input         | ​Title                                                                                                                                                                             |
| ------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| name          | <p><strong>Type:</strong> <code>String </code><em><code>required</code></em></p><p><code>The name for the combined ConanState that will be returned</code></p>                     |
| fromState     | <p><strong>Type:</strong> <code>{\[KEY in keyof T]: ConanState\<T\[KEY], any>} </code><em><code>required</code></em></p><p><code>the ConanState that we want to combine</code></p> |
| pipeThreadDef | <p><strong>Type:</strong> <code>PipeThreadDef\<T, {}, ACTIONS> </code><em><code>optional</code></em></p><p><code>TBC: Alberto que coño es esto</code> </p>                         |

| Returns                 | ​Title                            |
| ----------------------- | --------------------------------- |
| ConanState\<T, ACTIONS> | The resulting combined ConanState |

### *getEvents*

‌this method gives access to the ConanState main thread events

| Input | ​Title |
| ----- | ------ |
| void  |        |

| Returns                              | ​Title                                                      |
| ------------------------------------ | ----------------------------------------------------------- |
| FlowEventsTracker<{ nextData: DATA}> | all the events that have gone through the state main thread |

### *getName*

‌this method returns the ConantState name

| Input | ​Title |
| ----- | ------ |
| void  |        |

| Returns | ​Title              |
| ------- | ------------------- |
| string  | the ConanState name |

### *openTransaction*

‌this method allows to open a transaction

| Input | ​Title                                                                                                                                                                         |
| ----- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| name  | <p><strong>Type:</strong> <code>String </code><em><code>required</code></em></p><p><code>The name of the transaction to create to be used for internal logging only</code></p> |

| Returns | ​Title |
| ------- | ------ |
| void    |        |

### *closeTransaction*

‌this method allows to close the current transaction

| Input    | ​Title                                                                                                                                                              |
| -------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| callback | <p><strong>Type:</strong> <code>IConsumer\<DATA> </code><em><code>optional</code></em></p><p><code>callback to be invoked once the transaction is closed</code></p> |

| Returns | ​Title |
| ------- | ------ |
| void    |        |


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.conanjs.io/api/main-classes/conan-state.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
