import type { Observer } from '../../observer'; export declare class SubscriptionContainer { /** * Key/Name identifier of the Subscription Container. */ key?: SubscriptionContainerKeyType; /** * Whether the Subscription Container * and the UI-Component it represents are ready. * * When both instances are ready, * the Subscription Container is allowed * to trigger re-renders on the UI-Component. */ ready: boolean; /** * Unique identifier of the UI-Component * the Subscription Container represents. */ componentId?: ComponentIdType; /** * Observers that are subscribed to the Subscription Container. * * The subscribed Observers use the Subscription Container * as an interface to the UI-Component it represents. * * Through the Subscription Container, the Observers can easily trigger re-renders * on the UI-Component, for example, when their value updates. * * [Learn more..](https://agile-ts.org/docs/core/integration#-subscriptions) */ subscribers: Set; /** * Temporary stores the subscribed Observers, * that were updated by the runtime * and are currently running through * the update (rerender) Subscription Container (UI-Component) process. */ updatedSubscribers: Set; /** * Whether the Subscription Container is object based. * * A Subscription Container is object based when the subscribed Observers * have been provided in an Observer keymap object * ``` * { * state1: Observer, * state2: Observer * } * ``` * Thus each Observer has its 'external' unique key stored in the `subscribersWeakMap`. * * Often Component based Subscriptions are object based, * because each Observer requires in such Subscription a unique identifier. * Mainly to be properly represented in the `updatedData` object * sent to the Integration's `updateMethod()` method * when the Subscription Container updates (re-renders the UI-Component). */ isObjectBased: boolean; /** * Weak map for storing 'external' key identifiers for subscribed Observers. * * Why is the key not applied directly to the Observer? * * Because the key defined here should be only valid * for the scope of the Subscription Container. * * https://stackoverflow.com/questions/29413222/what-are-the-actual-uses-of-es6-weakmap */ subscriberKeysWeakMap: WeakMap; /** * Weak Map for storing selector functions for subscribed Observers. * * A selector function allows the partial subscription to an Observer value. * Only when the selected Observer value part changes, * the Subscription Container is updated (-> re-renders the UI-Component). * * Why are the selector functions not applied directly to the Observer? * * Because the selector function defined here should be only valid * for the scope of the Subscription Container. * * https://stackoverflow.com/questions/29413222/what-are-the-actual-uses-of-es6-weakmap */ selectorsWeakMap: SelectorWeakMapType; /** * A Subscription Container represents a UI-Component in AgileTs * that can be subscribed by multiple Observer Instances. * * The subscribed Observers can use the Subscription Container as an interface * to the UI-Component it represents. * For example, to trigger re-renders on the UI-Component, * when their value has changed. * * @internal * @param subs - Observers to be initial subscribed to the Subscription Container. * @param config - Configuration object */ constructor(subs: Array | { [key: string]: Observer; }, config?: SubscriptionContainerConfigInterface); /** * Subscribes the specified Observer to the Subscription Container. * * @internal * @param sub - Observer to be subscribed to the Subscription Container * @param config - Configuration object */ addSubscription(sub: Observer, config?: AddSubscriptionMethodConfigInterface): void; /** * Unsubscribes the specified Observer from the Subscription Container. * * @internal * @param sub - Observer to be unsubscribed from the Subscription Container. */ removeSubscription(sub: Observer): void; } export declare type SubscriptionContainerKeyType = string | number; export interface SubscriptionContainerConfigInterface { /** * Key/Name identifier of the Subscription Container * @default undefined */ key?: SubscriptionContainerKeyType; /** * Key/Name identifier of the UI-Component to be represented by the Subscription Container. * @default undefined */ componentId?: ComponentIdType; /** * A Weak Map with a set of proxy paths to certain properties * in an Observer value for subscribed Observers. * * These paths are then selected via selector functions * which allow the partly subscription to an Observer value. * Only if the selected Observer value part changes, * the Subscription Container re-renders the UI-Component it represents. * * For example: * ``` * WeakMap: { * Observer1: {paths: [['data', 'name']]}, * Observer2: {paths: [['car', 'speed']]} * } * ``` * Now the Subscription Container will only trigger a re-render on the UI-Component * if 'data.name' in Observer1 or 'car.speed' in Observer2 updates. * If, for instance, 'data.age' in Observer1 mutates it won't trigger a re-render, * since 'data.age' isn't represented in the specified Proxy Weak Map. * * These particular paths can, for example, be tracked via the ProxyTree. * https://github.com/agile-ts/agile/tree/master/packages/proxytree * * @default new WeakMap() */ proxyWeakMap?: ProxyWeakMapType; /** * A Weak Map with a set of selector functions for Observers. * * Selector functions allow the partly subscription to Observer values. * Only if the selected Observer value part changes, * the Subscription Container re-renders the UI-Component it represents. * * For example: * ``` * WeakMap: { * Observer1: {methods: [(value) => value.data.name]}, * Observer2: {methods: [(value) => value.car.speed]} * } * ``` * Now the Subscription Container will only trigger a re-render on the UI-Component * if 'data.name' in Observer1 or 'car.speed' in Observer2 updates. * If, for instance, 'data.age' in Observer1 mutates it won't trigger a re-render, * since 'data.age' isn't selected by any selector method in the specified Selector Weak Map. * * @default new WeakMap() */ selectorWeakMap?: SelectorWeakMapType; } export interface AddSubscriptionMethodConfigInterface { proxyPaths?: ProxyPathType[]; selectorMethods?: SelectorMethodType[]; key?: string; } export declare type ProxyPathType = string[]; export declare type ProxyWeakMapType = WeakMap; export declare type SelectorMethodType = (value: T) => any; export declare type SelectorWeakMapType = WeakMap[]; }>; export declare type ComponentIdType = string | number;