mirror of
https://github.com/zoriya/v10.git
synced 2026-08-16 02:45:09 +00:00
51 lines
2.0 KiB
TypeScript
51 lines
2.0 KiB
TypeScript
import { AnyStore } from "../../core/store.js";
|
|
import { StoreSource } from "../store-accessor.js";
|
|
import { ReactiveController, ReactiveControllerHost } from "@videojs/element";
|
|
//#region src/html/controllers/subscription-controller.d.ts
|
|
type SubscriptionControllerHost = ReactiveControllerHost & HTMLElement;
|
|
interface SubscriptionControllerConfig<Store extends AnyStore, Value> {
|
|
getValue: (store: Store) => Value;
|
|
subscribe: (store: Store, onChange: () => void) => () => void;
|
|
}
|
|
/**
|
|
* Resolves a store from context or direct source and manages subscription lifecycle.
|
|
*
|
|
* Combines store resolution (direct or context) with subscription management.
|
|
* Use as a building block for controllers that need store access with subscriptions.
|
|
*
|
|
* @example
|
|
* ```ts
|
|
* class MyController<Store extends AnyStore> {
|
|
* #ctrl: SubscriptionController<Store, Tasks>;
|
|
*
|
|
* constructor(host: Host, source: StoreSource<Store>) {
|
|
* this.#ctrl = new SubscriptionController(host, source, {
|
|
* subscribe: (store, onChange) => store.queue.subscribe(onChange),
|
|
* getValue: (store) => store.queue.tasks,
|
|
* });
|
|
* }
|
|
*
|
|
* get value() {
|
|
* return this.#ctrl.value;
|
|
* }
|
|
* }
|
|
* ```
|
|
*/
|
|
declare class SubscriptionController<Store extends AnyStore, Value> implements ReactiveController {
|
|
#private;
|
|
/**
|
|
* @param host - The host element that owns this controller.
|
|
* @param source - Store instance or context to resolve the store from.
|
|
* @param config - Subscription and value extraction configuration.
|
|
*/
|
|
constructor(host: SubscriptionControllerHost, source: StoreSource<Store>, config: SubscriptionControllerConfig<Store, Value>);
|
|
get value(): Value;
|
|
hostDisconnected(): void;
|
|
}
|
|
declare namespace SubscriptionController {
|
|
type Host = SubscriptionControllerHost;
|
|
type Config<Store extends AnyStore, Value> = SubscriptionControllerConfig<Store, Value>;
|
|
}
|
|
//#endregion
|
|
export { SubscriptionController, SubscriptionControllerConfig, SubscriptionControllerHost };
|
|
//# sourceMappingURL=subscription-controller.d.ts.map
|