View on GitHub

mo360-ftk

MO360 Frontend Toolkit: A toolkit for single page applications (SPA) based on React and Typescript that allows to extract single features into microfrontends.

Swidgets

Swidgets are one fundamental part of the FTK. Therefore it is good to know how you could use them the best way.

Base structure

For a swidget loading we have two components: The host app and the swidget app. The host app is the running standalone application which is directly accessible. The swidget is not directly runnable because of the compilation it is only a plain JavaScript file which contains all dependencies. The swidget must be loaded by a host app which renders it correctly for the user.

For this purpose the boilerplate has two build scripts:

The resulting JavaScript swidget is a plain JS file. It will contain something like this:

// The name is the mandatory thing. It is needed for loading the swidget.
// It is constructed from the package name in your package.json file
var nameOfYourSwidget = { lotOfStuffYouDontNeedDoUnderstand };

How to load a swidget?

The FTK provides an easy component for loading a swidget:

// Assume the swidget is accessible on a webserver: http://test.de/someSwidget.js
public render() {
  // The name must match the variable name in the JS file. Otherwise it will not load the swidget.
  return <Loader name={nameOfSwidgetApplication} url={'http://test.de/someSwidget.js'} />>;
}

What can I do with the swidget?

How to use interconnection?

To use the Interconnection you have to either inject the InterconnectionService or use the hook useInterconnection().

BUT!: keep in mind to keep the communication topics separated as needed. If not swidget/host could intercept the communication they should not be aware of. As an easy advise you could use generated UUID from the host and provided to the swidgets via props.

What I should care about?