Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Initializable

Mixin that incorporates basic (un-)initialization workflow. The inheritor should specialize initialize and uninitialize and decorate them with @initialize and @uninitialize respectively. When the object gets constructed it is not initialized. It can be initialized only when it is not initialized and uninitialized vice versa. Failure states result in invalid asserts. The initialization status within the inheritor can be asserted using assertInitialized and assertUninitialized. Note that the use of this class requires decorator support (compilerOptions: experimentalDecorators: true). ` class Test extends Initializable {

@initialize()
initialize(name: string): boolean {
    ....
    return true;
}

@uninitialize()
uninitialize(): void {
    ...
}

doStuffWhenInitialized(): void {
    this.assertInitialized();
    ...
}
// ... or alternatively:
@assert_initialized()
doOtherStuffWhenInitialized(): void {
    ...
}

`

Hierarchy

Index

Properties

Private _initialized

_initialized: boolean = false

Accessors

initialized

  • get initialized(): boolean
  • Property getter for readonly access to the initialization status of an initializable instance.

    Returns boolean

Methods

Protected assertInitialized

  • assertInitialized(): void
  • Asserts the objects initialization status to be true. Note that the implementation is cached and forwarded to either an empty function when initialized and to an acutal assert(false) otherwise.

    Returns void

Protected assertUninitialized

  • assertUninitialized(): undefined
  • Asserts the objects initialization status to be false. Note that the implementation is cached and forwarded to either an empty function when uninitialized and to an acutal assert(false) otherwise.

    Returns undefined

Abstract initialize

  • initialize(...args: any[]): boolean
  • Should implement actual initialization and has to be decorated by @initialize in order to assert initialization status and update the initialization status (based on return value).

    Parameters

    • Rest ...args: any[]

      All args are passed to the onInitialize function a subclass must override.

    Returns boolean

    • True if initialization was successful.

Abstract uninitialize

  • uninitialize(): void
  • Uninitialization event that should be specialized by inheritor and has to be decorated by @uninitialize in order to assert initialization status and set the initialization status to false.

    Returns void

Static Protected assertInitializedFalse

Static Protected assertUninitializedFalse

Static assert_initialized

Static assert_uninitialized

Static initialize

  • Method decorator for initialization of Initializable inheritors. This decorator asserts the initialization status of the instance that is to be initialized, invokes its initialization with arbitrary number of parameters, and sets the initialization status to the initialization success (either false or true). In order to encourage the use of assertInitialized and assertUninitialized they are dynamically bound to either a static, always-failing assert or an empty/undefined function.

    Returns MethodDecorator

Static uninitialize

  • Method decorator for uninitialization of Initializable inheritors. This decorator asserts the initialization status of the instance that is to be uninitialized, invokes its uninitialization, and falsifies the initialization status. In order to encourage the use of assertInitialized and assertUninitialized they are dynamically bound to a static, always-failing assert and an empty/undefined function respectively.

    Returns MethodDecorator