import { SharedAPI } from '../abstractions'; import { Bento } from '../Bento'; import { EventEmitterLike } from '../interfaces'; import { ComponentReference, PluginReference } from '../references'; import { VariableDefinition } from '../variables'; import { Component } from './interfaces'; /** * The gateway of a component to the rest of the application. * Each component gets one if loaded. */ export declare class ComponentAPI extends SharedAPI { /** * The component this API object belongs to */ private readonly component; /** * Currently existing subscriptions of this component. * The key is the namespace where a subscription was added, * the value is an array of subscription ids on that namespace. */ private readonly subscriptions; constructor(bento: Bento, component: Component); /** * Inject component dependency into invoking component * @param reference Component name or reference * @param injectName property name to inject into */ injectComponent(reference: ComponentReference, injectName: string): void; /** * Invokes a plugins loadComponents method. Allowing for easy loading of peer/children components * @param reference Plugin name or reference * @param args Arguments to be passed to Plugin.loadComponents() method * * @returns Plugin.loadComponents() result */ loadComponents(reference: PluginReference, ...args: Array): Promise; /** * Inject plugin into invoking component * @param reference Plugin name or reference * @param injectName property name to inject into */ injectPlugin(reference: PluginReference, injectName: string): void; /** * Defines and attaches a variable to component * @param definition Variable definition * @param injectName property name to inject into */ injectVariable(definition: VariableDefinition, injectName?: string): void; /** * Emit a event on Component Events * @param eventName Name of event * @param args Ordered Array of args to emit */ emit(eventName: string, ...args: Array): Promise; /** * Emit subject event on Component Events * @param eventName Name of event * @param args Ordered Array of args to emit */ emitSubject(eventName: string, ...args: Array): Promise; /** * Re-emits events from a standard event emitter into component events. * * @param fromEmitter Emitter to re-emit from * @param events Events to watch for * * @throws IllegalStateError if the emitter on the current component wasn't initialized * @throws IllegalArgumentError if fromEmitter is not an EventEmitter or events is not an array */ forwardEvents(fromEmitter: EventEmitterLike, events: Array): void; /** * Subscribe to a Component event * @param reference Component Reference / Name * @param name Name of the event * @param handler The function to be called * @param context Optional `this` context for prior handler function * * @returns Subscription ID */ subscribe(reference: ComponentReference, name: string, handler: (...args: Array) => void, context?: any): number; /** * Alias for subscribe with normal event * @param reference Component Reference / Name * @param eventName Name of the event * @param handler The function to be called * @param context Optional `this` context for above handler function * * @deprecated * * @returns Subscription ID */ subscribeEvent(reference: ComponentReference, eventName: string, handler: (...args: Array) => void, context?: any): number; /** * Ubsubscribe from a Component Event * @param reference - Component Reference / Name * @param id - subscription id provided by subscribe */ unsubscribe(reference: ComponentReference, id: number): void; /** * Unsubscribes from all events in a namespace or all events alltogether. * This will automatically get called when your component gets unloaded * * @param reference - Optional. A namespace where all events should be unsubscribed */ unsubscribeAll(reference?: ComponentReference): void; }