> For the complete documentation index, see [llms.txt](https://angularjs-store.gitbook.io/docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://angularjs-store.gitbook.io/docs/v4.0.0/tutorials/update-the-state.md).

# 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 are also able to make some parts of your application that uses the same store to notice the changes.

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

```typescript
import { CounterState, CounterStore } from 'counter-store';

function YourController(counterStore: CounterStore) {
  let currentState: CounterState;

  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 first the current state because you used it for computation.

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

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

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

function YourController(counterStore: 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 %}
