Skip to content

CodeCoupler UI Internals

This informations are used internally. Normally you never have to use this.

Async Contructor Pattern

The base class of all components implements an async constructor pattern. Classes derived from here can initiated with:

1
let myClass = new MyClass().initialized.then(/*...*/).catch(/*...*/);

Or with:

1
2
let myClass = new MyClass();
await myClass.initialized;

The constructor of the base class call for these async methods behind each other: prepare, init, finalize.

The prepare and finalize methods are used internally by the base class and components. Classes implemented by the user that derive from components have to implement their asynchronous initialization procedure within the init method:

1
2
3
4
5
class MyClass extends SomeComponent {
  async init(options) {
    //Do something
  }
}

The prepare method receive the arguments as they are used in the instantiation of the class. In most cases the components override the prepare method to prepare the expected arguments or do other initializations.

Normally the user does not instatiate a component directly, except for the System component. He use the component factory methods like app(), stage() and widget(). In these methods the environment for the prepare method will be prepared and the component will be instantiated. These methods also take care of error handling if necessary.

If the return value of the prepare method is false, init will not be executed.

The finalize method do receive the return value of the init method as first argument and the return value of prepare as second argument. The method will be only executed if prepare and init do not throw any errors.

Whenever one of the methods prepare, init or finalize will throw an exception, the promise initialized will be rejected with a custom error type "ComponentInitError`. This error type do not have a stack, because this stack would only include the trace inside of the construction construct. It contains two properties with more informations:

cause: Contains the origin error that was thrown. If an error object was thrown you will find here the relevant stack informations. component: The component instance that throwed the error.

Back to top