@robotlegsjs/core
Version:
An architecture-based IoC framework for JavaScript/TypeScript
166 lines (165 loc) • 4.26 kB
TypeScript
/**
* The Robotlegs object lifecycle contract
*/
export interface ILifecycle {
/**
* The current lifecycle state of the target object
*/
state: string;
/**
* The target object associated with this lifecycle
*/
target: any;
/**
* Is this object uninitialized?
*/
uninitialized: boolean;
/**
* Has this object been fully initialized?
*/
initialized: boolean;
/**
* Is this object currently active?
*/
active: boolean;
/**
* Has this object been fully suspended?
*/
suspended: boolean;
/**
* Has this object been fully destroyed?
*/
destroyed: boolean;
/**
* Initializes the lifecycle
*
* @param callback Initialization callback
*/
initialize(callback?: Function): void;
/**
* Suspends the lifecycle
*
* @param callback Suspension callback
*/
suspend(callback?: Function): void;
/**
* Resumes a suspended lifecycle
*
* @param callback Resumption callback
*/
resume(callback?: Function): void;
/**
* Destroys an active lifecycle
*
* @param callback Destruction callback
*/
destroy(callback?: Function): void;
/**
* A handler to run before the target object is initialized
*
* <p>The handler can be asynchronous. See: readme-async</p>
*
* @param handler Pre-initialize handler
* @return Self
*/
beforeInitializing(handler: Function): ILifecycle;
/**
* A handler to run during initialization
*
* <p>Note: The handler must be synchronous.</p>
*
* @param handler Initialization handler
* @return Self
*/
whenInitializing(handler: Function): ILifecycle;
/**
* A handler to run after initialization
*
* <p>Note: The handler must be synchronous.</p>
*
* @param handler Post-initialize handler
* @return Self
*/
afterInitializing(handler: Function): ILifecycle;
/**
* A handler to run before the target object is suspended
*
* <p>The handler can be asynchronous. See: readme-async</p>
*
* @param handler Pre-suspend handler
* @return Self
*/
beforeSuspending(handler: Function): ILifecycle;
/**
* A handler to run during suspension
*
* <p>Note: The handler must be synchronous.</p>
*
* @param handler Suspension handler
* @return Self
*/
whenSuspending(handler: Function): ILifecycle;
/**
* A handler to run after suspension
*
* <p>Note: The handler must be synchronous.</p>
*
* @param handler Post-suspend handler
* @return Self
*/
afterSuspending(handler: Function): ILifecycle;
/**
* A handler to run before the target object is resumed
*
* <p>The handler can be asynchronous. See: readme-async</p>
*
* @param handler Pre-resume handler
* @return Self
*/
beforeResuming(handler: Function): ILifecycle;
/**
* A handler to run during resumption
*
* <p>Note: The handler must be synchronous.</p>
*
* @param handler Resumption handler
* @return Self
*/
whenResuming(handler: Function): ILifecycle;
/**
* A handler to run after resumption
*
* <p>Note: The handler must be synchronous.</p>
*
* @param handler Post-resume handler
* @return Self
*/
afterResuming(handler: Function): ILifecycle;
/**
* A handler to run before the target object is destroyed
*
* <p>The handler can be asynchronous. See: readme-async</p>
*
* @param handler Pre-destroy handler
* @return Self
*/
beforeDestroying(handler: Function): ILifecycle;
/**
* A handler to run during destruction
*
* <p>Note: The handler must be synchronous.</p>
*
* @param handler Destruction handler
* @return Self
*/
whenDestroying(handler: Function): ILifecycle;
/**
* A handler to run after destruction
*
* <p>Note: The handler must be synchronous.</p>
*
* @param handler Post-destroy handler
* @return Self
*/
afterDestroying(handler: Function): ILifecycle;
}