# @autoSubscribe

Legacy decorator that re-runs a method whenever one of the store values it reads is assigned. For new code, prefer [@subscribe](/docs/decorators/subscribe) with a [`DataProviderKey`](/docs/misc/dataProviderKey): dependencies are explicit and typed.

## Import

<sonic-code language="typescript">
  <template>
import { autoSubscribe } from "@supersoniks/concorde/decorators";
import { get } from "@supersoniks/concorde/utils";

@autoSubscribe()
updateDisplay() {
  this.total = get(passengersKey) + get(crewKey);
}
  </template>
</sonic-code>

## Tracked reads

The method runs once after `connectedCallback`. Every store value read during that run becomes a dependency; assigning any of them runs the method again. Write the result to a `@state()` property (or call `requestUpdate()`) so the component re-renders.

<sonic-code>
  <template>
    <docs-demo-sources for="demo-auto-subscribe"></docs-demo-sources>
    <demo-auto-subscribe></demo-auto-subscribe>
  </template>
</sonic-code>

## Notes

- Several assignments in the same task trigger a single re-run (batched with `queueMicrotask`).
- Keep reads unconditional: a value read only behind a condition becomes a dependency the first time that branch runs.
- Subscriptions are removed in `disconnectedCallback`.

## API reference

| Argument | Type | Description |
|----------|------|-------------|
| none | | `@autoSubscribe()` takes no argument; apply it to a method of a custom element |
