# SubscriptionController

Reactive controller that resolves a store and manages a derived subscription

## Import

```ts
import { SubscriptionController } from "@videojs/store/html";
```

## Usage

Provide a store or store context plus functions that read the current value and subscribe to changes.

```ts
class QueueController {
  readonly #tasks;

  constructor(host, storeSource) {
    this.#tasks = new SubscriptionController(host, storeSource, {
      getValue: (store) => store.queue.tasks,
      subscribe: (store, onChange) => store.queue.subscribe(onChange),
    });
  }

  get value() {
    return this.#tasks.value;
  }
}
```

The controller requests a host update when the subscription changes and unsubscribes when the host disconnects. Reading `value` throws until a store is available.

## API Reference

`new SubscriptionController<Store extends AnyStore, Value>(host, source, config)`

### Parameters

| Parameter | Type | Default | Description |
| --- | --- | --- | --- |
| `host` (required) | `{ addController(controller: ReactiveController): void; removeController(controller: ReactiveController): void; requestUpdate(): void; updateComplete: Promise<boolean> } & HTMLElement` | — | The host element that owns this controller. |
| `source` (required) | `Store \| Context<unknown, Store>` | — | Store instance or context to resolve the store from. |
| `config` (required) | `{ getValue: ((store: Store) => Value); subscribe: ((store: Store, onChange: (() => void)) => (() => void)) }` | — | Subscription and value extraction configuration. |

### Return Value

| Property | Type |
| --- | --- |
| `value` | `Value` |

---

HTML documentation: https://videojs.org/docs/framework/html/llms.txt
All documentation: https://videojs.org/llms.txt
