# Update the state

In AngularJS Store, the only way to update the state from the store is by dispatching an action. By using the `dispatch` method, you're also able to notify some parts of your application that uses the same store.

{% code title="your-controller.js" %}

```javascript
import { CounterStore } from 'counter-store';

function YourController(counterStore) {
  let currentState;

  currentState = counterStore.copy();
  counterStore.dispatch('INCREMENT_COUNT', {
    count: currentState.count + 1;
  });

  currentState = counterStore.copy();
  counterStore.dispatch('DECREMENT_COUNT', {
    count: currentState.count - 1;
  });
}

angular
  .module('App', [])
  .controller('YourController', YourController);
```

{% endcode %}

As you can notice in the above example, every time you perform an update to the state, you get the current state first because you used it for computation.

`dispatch` method has a simple way for that scenario that you can use.

{% code title="your-controller.js" %}

```javascript
import { CounterStore } from 'counter-store';

function YourController(counterStore) {
  counterStore.dispatch('INCREMENT_COUNT', (currentState) => {
    return { count: currentState.count + 1 };
  });

  counterStore.dispatch('DECREMENT_COUNT', (currentState) => {
    return { count: currentState.count - 1 };
  });
}

angular
  .module('App', [])
  .controller('YourController', YourController);
```

{% endcode %}


---

# 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://angularjs-store.gitbook.io/docs/tutorials-with-javascript/update-the-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.
