import type { Agile } from '../../agile'; import type { SubscriptionContainer, SubscriptionContainerConfigInterface } from './container/SubscriptionContainer'; import { ComponentSubscriptionContainer } from './container/ComponentSubscriptionContainer'; import { CallbackSubscriptionContainer } from './container/CallbackSubscriptionContainer'; import type { Observer } from '../observer'; export declare class SubController { agileInstance: () => Agile; componentSubs: Set; callbackSubs: Set; mountedComponents: Set; /** * The Subscription Controller manages and simplifies the subscription to UI-Components. * * Thus it creates Subscription Containers (Interfaces to UI-Components) * and assigns them to the specified Observers. * These Observers can then easily trigger re-renders on UI-Components * via the created Subscription Containers. * * @internal * @param agileInstance - Instance of Agile the Subscription Controller belongs to. */ constructor(agileInstance: Agile); /** * Creates a so called Subscription Container that represents an UI-Component in AgileTs. * Such Subscription Container know how to trigger a re-render on the UI-Component it represents * through the provided `integrationInstance`. * * Currently, there are two different ways the Subscription Container can trigger a re-render on the UI-Component. * - 1. Via a callback function that directly triggers a rerender on the UI-Component. * (= Callback based Subscription) * [Learn more..](https://agile-ts.org/docs/core/integration/#callback-based) * - 2. Via the Component instance itself. * For example by mutating a local State Management property. * (= Component based Subscription) * [Learn more..](https://agile-ts.org/docs/core/integration/#component-based) * * The in an array specified Observers are then automatically subscribed * to the created Subscription Container and thus to the UI-Component it represents. * * @public * @param integrationInstance - Callback function or Component Instance to trigger a rerender on a UI-Component. * @param subs - Observers to be subscribed to the to create Subscription Container. * @param config - Configuration object */ subscribe(integrationInstance: any, subs: Array, config?: RegisterSubscriptionConfigInterface): SubscriptionContainer; /** * Creates a so called Subscription Container that represents an UI-Component in AgileTs. * Such Subscription Container know how to trigger a re-render on the UI-Component it represents * through the provided `integrationInstance`. * * Currently, there are two different ways the Subscription Container can trigger a re-render on the UI-Component. * - 1. Via a callback function that directly triggers a rerender on the UI-Component. * (= Callback based Subscription) * [Learn more..](https://agile-ts.org/docs/core/integration/#callback-based) * - 2. Via the Component instance itself. * For example by mutating a local State Management property. * (= Component based Subscription) * [Learn more..](https://agile-ts.org/docs/core/integration/#component-based) * * The in an object keymap specified Observers are then automatically subscribed * to the created Subscription Container and thus to the UI-Component it represents. * * The advantage of subscribing the Observer via a object keymap, * is that each Observer has its own unique 'external' key identifier. * Such key identifier is, for example, required when merging the Observer value into * a local UI-Component State Management property. * ``` * this.state = {...this.state, {state1: Observer1.value, state2: Observer2.value}} * ``` * * @public * @param integrationInstance - Callback function or Component Instance to trigger a rerender on a UI-Component. * @param subs - Observers to be subscribed to the to create Subscription Container. * @param config - Configuration object */ subscribe(integrationInstance: any, subs: { [key: string]: Observer; }, config?: RegisterSubscriptionConfigInterface): { subscriptionContainer: SubscriptionContainer; props: { [key: string]: Observer['value']; }; }; /** * Removes the Subscription Container extracted from the specified 'subscriptionInstance' * from all Observers that were subscribed to it. * * We should always unregister a Subscription Container when it is no longer in use. * For example, when the UI-Component it represents has been unmounted. * * @public * @param subscriptionInstance - UI-Component that contains an instance of a Subscription Container * or a Subscription Container to be unsubscribed/unregistered. */ unsubscribe(subscriptionInstance: any): void; /** * Returns a newly created Component based Subscription Container. * * @internal * @param componentInstance - UI-Component to be represented by the Subscription Container * and mutated via the Integration's 'updateMethod()' method to trigger re-renders on it. * @param subs - Observers to be initial subscribed to the Subscription Container. * @param config - Configuration object. */ createComponentSubscriptionContainer(componentInstance: any, subs: { [key: string]: Observer; } | Array, config?: RegisterSubscriptionConfigInterface): ComponentSubscriptionContainer; /** * Returns a newly created Callback based Subscription Container. * * @internal * @param callbackFunction - Callback function to cause a rerender on the Component * to be represented by the Subscription Container. * @param subs - Observers to be initial subscribed to the Subscription Container. * @param config - Configuration object */ createCallbackSubscriptionContainer(callbackFunction: () => void, subs: { [key: string]: Observer; } | Array, config?: RegisterSubscriptionConfigInterface): CallbackSubscriptionContainer; /** * Notifies the Subscription Containers representing the specified UI-Component (`componentInstance`) * that the UI-Component they represent has been mounted. * * @public * @param componentInstance - Component Instance containing Subscription Containers to be mounted. */ mount(componentInstance: any): void; /** * Notifies the Subscription Containers representing the specified UI-Component (`componentInstance`) * that the UI-Component they represent has been unmounted. * * @public * @param componentInstance - Component Instance containing Subscription Containers to be unmounted */ unmount(componentInstance: any): void; } export interface RegisterSubscriptionConfigInterface extends SubscriptionContainerConfigInterface { /** * Whether the Subscription Container shouldn't be ready * until the UI-Component it represents has been mounted. * @default agileInstance.config.waitForMount */ waitForMount?: boolean; }