Skip to main content

# CMicroAppGuest<AppObjects, AppEvents>

Micro-frontend guest application class (singleton). Manages communication between a guest micro-app and its host application. Supports both SSF (Shared Service Framework) and App Bridge communication methods.

## Example​

    const guest = new CMicroAppGuest({
      onInit: ({ history, theme, prevState }) => {
        console.log('Guest initialized');
      },
      onMount: ({ container }) => {
        // Render your React app
        ReactDOM.render(<App />, container);
      },
      onUnmount: ({ container }) => {
        // Cleanup
        ReactDOM.unmountComponentAtNode(container);
        return { savedState: 'some data' };
      }
    });

## Type Parameters​

### AppObjects​

`AppObjects` extends `ScriptingObjects` = `Partial`<`ScriptingObjectTypes`>

Type of custom scripting objects

### AppEvents​

`AppEvents` extends `EventListeners` = `Events`

Type of custom event listeners

## Implements​

- `IMicroAppGuest`<`AppObjects`, `AppEvents`>

## Accessors​

### uuid​

#### Get Signature​

    get uuid(): string;

Unique identifier for the microapp instance.

##### Returns​

`string`

#### Implementation of​

    IMicroAppGuest.uuid

## Methods​

### addScriptingObject()​

    addScriptingObject<SO>(so: SO, params?: AddScriptingObjectParams): void;

add scripting object for child microapp to use

#### Type Parameters​

##### SO​

`SO` extends `IScriptingObject`

#### Parameters​

##### so​

`SO`

The scripting object to be added.

##### params?​

`AddScriptingObjectParams`

Optional parameters for adding the scripting object.

#### Returns​

`void`

#### Implementation of​

    IMicroAppGuest.addScriptingObject

### dispatchEvent()​

    dispatchEvent<EventId, Params, Options>(params: DispatchEventParam<EventId, Params, Options>): Promise<void | any[]>;

Dispatches an event to the child microapp.

#### Type Parameters​

##### EventId​

`EventId` extends `string`

##### Params​

`Params` extends `any`

##### Options​

`Options` extends `EventOptions`

#### Parameters​

##### params​

`DispatchEventParam`<`EventId`, `Params`, `Options`>

Event parameters.

#### Returns​

`Promise`<`void` | `any`[]>

A promise that resolves with the combined results of dispatched events.

#### Implementation of​

    IMicroAppGuest.dispatchEvent

### getHost()​

    getHost():
      | IMicroAppHost<Partial<ScriptingObjectTypes>, Events>
      | IMicroFEHost<Partial<ScriptingObjectTypes>, Events>
      | SSFGuest<Partial<ScriptingObjectTypes>, Events>
      | undefined;

#### Returns​

| `IMicroAppHost`<`Partial`<`ScriptingObjectTypes`>, `Events`> | `IMicroFEHost`<`Partial`<`ScriptingObjectTypes`>, `Events`> | `SSFGuest`<`Partial`<`ScriptingObjectTypes`>, `Events`> | `undefined`

### getLogger()​

    getLogger(): MicroFrontEndLogger;

#### Returns​

`MicroFrontEndLogger`

### getObject()​

    getObject<ObjectId>(objectId: ObjectId): Promise<AppObjects[ObjectId] | null>;

Retrieves a reference to a scripting object (or proxy) by its unique name.

#### Type Parameters​

##### ObjectId​

`ObjectId` extends `string`

#### Parameters​

##### objectId​

`ObjectId`

The unique name of the scripting object.

#### Returns​

`Promise`<`AppObjects`[`ObjectId`] | `null`>

A promise that resolves to the scripting object reference or `null` if not found.

#### Implementation of​

    IMicroAppGuest.getObject

### getProps()​

    getProps(): GuestProps<Partial<ScriptingObjectTypes>, Events>;

#### Returns​

`GuestProps`<`Partial`<`ScriptingObjectTypes`>, `Events`>

### getRef()​

    getRef<T>(): T | null;

Retrieves a generic reference of type `T`.

#### Type Parameters​

##### T​

`T`

#### Returns​

`T` | `null`

The reference of type `T` or `null` if not available.

#### Deprecated​

This method is deprecated and will be removed in future versions.

#### Implementation of​

    IMicroAppGuest.getRef

### init()​

    init(options: InitOptions<AppObjects, AppEvents>): Promise<void>;

Initializes the microapp with the provided options.

#### Parameters​

##### options​

`InitOptions`<`AppObjects`, `AppEvents`>

Options for initializing the microapp.

#### Returns​

`Promise`<`void`>

A promise that resolves when initialization is complete.

#### Implementation of​

    IMicroAppGuest.init

### mount()​

    mount(options: MountOptions): Promise<void>;

Mounts the microapp with the provided options.

#### Parameters​

##### options​

`MountOptions` = `...`

Options for mounting the microapp.

#### Returns​

`Promise`<`void`>

A promise that resolves when the microapp is successfully mounted.

#### Implementation of​

    IMicroAppGuest.mount

### navigate()​

    navigate(url: To, state?: any): void;

Navigates the microapp to a specified URL with an optional state.

#### Parameters​

##### url​

`To`

The target URL to navigate to.

##### state?​

`any`

Optional state to pass during navigation.

#### Returns​

`void`

#### Implementation of​

    IMicroAppGuest.navigate

### removeScriptingObject()​

    removeScriptingObject(objectId: Extract<keyof AppObjects, string>): void;

removes scripting object from child microapp use

#### Parameters​

##### objectId​

`Extract`<keyof `AppObjects`, `string`>

unique id of the scripting object

#### Returns​

`void`

#### Implementation of​

    IMicroAppGuest.removeScriptingObject

### subscribe()​

    subscribe<EventId>(params: SubscribeParam<EventId, AppEvents[EventId]>): string;

subscribe to the scripting object event

#### Type Parameters​

##### EventId​

`EventId` extends `string`

#### Parameters​

##### params​

`SubscribeParam`<`EventId`, `AppEvents`[`EventId`]>

the parameters for the subscription

#### Returns​

`string`

#### Implementation of​

    IMicroAppGuest.subscribe

### unmount()​

    unmount(options: MountOptions): Promise<JSONValue>;

Unmounts the microapp with the provided options.

#### Parameters​

##### options​

`MountOptions`

Options for unmounting the microapp.

#### Returns​

`Promise`<`JSONValue`>

A promise that resolves to a JSON value upon successful unmounting.

#### Implementation of​

    IMicroAppGuest.unmount

### unsubscribe()​

    unsubscribe<EventId>(params: UnsubscribeParam<EventId>): void;

unsubscribe from the scripting object event

#### Type Parameters​

##### EventId​

`EventId` extends `string`

#### Parameters​

##### params​

`UnsubscribeParam`<`EventId`>

parameters for the unsubscription

#### Returns​

`void`

#### Implementation of​

    IMicroAppGuest.unsubscribe

### getInstance()​

    static getInstance<AppObjects, AppEvents>(params?: ConstructorParams): CMicroAppGuest<AppObjects, AppEvents>;

#### Type Parameters​

##### AppObjects​

`AppObjects` extends `ScriptingObjects` = `Partial`<`ScriptingObjectTypes`>

##### AppEvents​

`AppEvents` extends `EventListeners` = `Events`

#### Parameters​

##### params?​

`ConstructorParams`

#### Returns​

`CMicroAppGuest`<`AppObjects`, `AppEvents`>

### isHosted()​

    static isHosted(): boolean;

#### Returns​

`boolean`

### isInitialized()​

    static isInitialized(): boolean;

#### Returns​

`boolean`