import type { DataProviderKey, DataProviderKeyHost, } from "../../utils/dataProviderKey"; import { bind } from "./bind"; /** * Read-only subscription to a publisher path via DataProviderKey<T>. No reflect. * The decorated property is typed as `T` (or optional / `| null` / `| undefined` for Lit / TSĀ 5). * Supports dynamic paths: use placeholders like "users.${userIndex}" in the DataProviderKey. * * @example * const dataKey = new DataProviderKey("data"); * @subscribe(dataKey.count) * @state() * count: number; * * // Dynamic path: * @subscribe(new DataProviderKey("users.${userIndex}")) * user: User | null; */ export function subscribe( key: DataProviderKey, ): ( target: DataProviderKeyHost & { [P in K]?: T | null | undefined }, propertyKey: K, ) => void { return bind(key) as ( target: DataProviderKeyHost & { [P in K]?: T | null | undefined }, propertyKey: K, ) => void; }