# Events

Every fundamental ActiveJS construct has a number of built-in Observable events. You can listen to these events by subscribing to the `events$` Observable, a property of every fundamental construct.

[Units](https://docs.activejs.dev/activejs/fundamentals/units), [Systems](https://docs.activejs.dev/activejs/fundamentals/systems), [Action](https://docs.activejs.dev/activejs/fundamentals/action), and [Cluster](https://docs.activejs.dev/activejs/fundamentals/cluster) have a common `EventReplay` event, it is triggered on a successful manual replay when you call the `replay()` method.

[Units](https://docs.activejs.dev/activejs/fundamentals/units) have many Units specific events that let you tap into all the action that's happening on a Unit.\
Every Unit has some common events like `EventUnitDispatch`, `EventUnitDispatchFail` and`EventUnitFreeze` etc.

[ListUnit](https://docs.activejs.dev/activejs/fundamentals/units/listunit) and [DictUnit](https://docs.activejs.dev/activejs/fundamentals/units/dictunit) have even more events specific to them, like `EventDictUnitSet`, `EventListUnitPush` or `EventListUnitPop` etc.

See [API reference](https://api.activejs.dev/index.html#baseevents) for more details.

## Listening to events

```typescript
const theAction = new Action(); // can also be a Unit, System or Cluster

theAction.events$.subscribe(event => {
    // Action, AsyncSystem and Cluster only have one event
    // so filtering is optional
    if(event instanceof EventReplay) {
        console.log('hey, you got replayed');
    }
});

// dispatch a value
theAction.dispatch('order order');
// this won't trigger any event, only Units emit an event on dispatch 

// replay the value
theAction.replay(); // it'll trigger the EventReplay event
```


---

# 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.activejs.dev/activejs/guides/events.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.
