XbBaseLayout

Overview


XbBaseLayout is a component used to construct the layout of a page.

The idea to construct the layout is by using vue slot

XbBaseLayout component has 3 types (base, main-side-navigation, base-side-navigation), where each type provides different vue slot template and different layout position. Hence, you must define the type using type props in order use this component.

Layout Types


Base

This layout type consist of three vue slot templates

  • Topbar
  • Main
  • Bottombar

On the micro-frontend architecture, this layout usually placed in common service.

Here is the illustration of base layout with corresponding slot templates.

layout base illustration

Communication Between Slot Components


The communication between slot components is established and implemented by using vue composable .

The composable provides 2 functions (dispatchLayoutEvent and listenLayoutEvent):

  • dispatchLayoutEvent is used to dispatch the event
  • listenLayoutEvent is used to listen the dispatched event

As an example, if you want to implement communication between the topbar, main, and bottombar. You should write code to emit and listen events from each components.

You also should specify the parameter correctly in order to communicate between the corresponding components. There is no absolute convention about this, but you can follow the example below to write the parameter syntax.

Notes

Composable only can be used if the components are in the same service/same project repository.

When working with micro-frontend architecture, you cannot use the composable directly to implement communication between components in the different services (e.g topbar-sidebar, as mentioned above, the topbar is usually located in common service and sidebar is located in other each service).

To establish communication between components in different services, you should use pub-sub pattern from xbase-js library.

But, in the example below since all the slot components are placed in the same project repository, the communication is established by using the composable

Composable


Here is the composable event emitter and listener code, you can use.

Powered by XBase 2.0

© 2023 Xtremax Pte Ltd