import { TDMModel } from '@tdm/core'; import { ResourceEventDispatcher, ResourceEventEmitter, ExecuteInitResourceEventArgs, ResourceEvent } from './events'; export interface RecordControlState { busy: boolean; } export declare type ResourceControlToken = Promise | T; export declare type ResourceEventListener = (this: ResourceControl, event: ResourceEvent) => void; /** * An controller, state and notification interface for instances of TDM models. * Each model instance has a corresponding ResourceControl instance. * * To get the ResourceControl instance for a specific model instance call ResourceControl#get(modelInstance) * * > If you are using the `ActiveRecord` plugin you can also opt in to have a property on each model instance * that reference the ResourceControl instance. * * Notifications are stream of resource related events, derived from {@link ResourceEvent}. * Each event is bound to a resource instance, hence every event fired in a ResourceControl instance * is an event bound to the resource. * * The notification are passive lifecycle event, intended to be used by the consumer of a resource. * Passive hooks does not effect actions, they are used for state (UI) representation. * * For active lifecycle hooks, being able to effect an action, use metadata life cycle hooks (`ActiveRecordHooks`) * */ export declare class ResourceControl implements RecordControlState { parent: TDMModel & T; /** * A stream of `ResourceEvent` see `ResourceEventType` for possible events. */ events$: ResourceEventEmitter; /** * Indicates if the active record is busy performing an action. */ readonly busy: boolean; protected dispatcher: ResourceEventDispatcher; protected actionCancel: () => void; protected lastExecute: ExecuteInitResourceEventArgs; protected state: RecordControlState; protected _next: Promise & T>; protected _mode: 'promise' | 'instance'; protected constructor(parent: TDMModel & T); /** * Set a new state value * @param key * @param value */ set

>(key: P, value: RecordControlState[P]): void; /** * Returns a promise, resolving on the next response from the current resource. * Will throw is there is no active action for this resource (i.e. not busy) * @returns */ next(silent?: boolean): Promise & T>; /** * Cancel the current action. * Does not throw if no action is running. */ cancel(): void; /** * Initialize the event system, return the dispatcher and emitter * * Derived implementations can implement different mechanisms */ protected initEventSys(): { dispatcher: ResourceEventDispatcher; emitter: ResourceEventEmitter; }; static addEventListener(handler: ResourceEventListener): void; static removeEventListener(handler: ResourceEventListener): boolean; /** * Returns a resource control for an instance of a resource. * If it's an instance and a resource control does not exist it will create it. * If it's a promise for a resource, will return it only if a resource was already created. */ static get(instance: ResourceControlToken): ResourceControl | undefined; /** * Emits an `ResourceEvent` in the `ActiveRecordState#.$events` of a `BaseResource` * @internal * @param event */ protected static emitEvent(event: ResourceEvent): void; private static _; }