Skip to content

Commit 91db8e4

Browse files
committed
docs: Add information about multiple plugins registered in a deferred way
1 parent 60884bb commit 91db8e4

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

modules/ROOT/pages/developers/applications.adoc

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ everything is ready for bootstrapping Hawtio and rendering `<Hawtio>` component.
9494
There are 3 methods of registering Hawtio plugins:
9595

9696
* using `hawtio.addPlugin()`: adds `Plugin` object directly for Hawtio to register
97-
* using `hawtio.addDeferredPlugin()`: adds a function which returns a Promise resolving to a `Plugin` object asynchronously
97+
* using `hawtio.addDeferredPlugin()`: adds a function which returns a Promise resolving to a `Plugin` object or an array of `Plugin` objects asynchronously
9898
* using `hawtio.addUrl()`: adds a URL (relative or absolute - subject to https://developer.mozilla.org/en-US/docs/Web/HTTP/Guides/CORS[CORS] restrictions) from which a JSON array of `HawtioRemote` objects is loaded. These objects represent remote modules which Hawtio can load and evaluate using https://www.npmjs.com/package/@module-federation/utilities[Module Federation utilities].
9999

100100
=== Registration of custom plugins
@@ -209,6 +209,7 @@ Hawtio plugins (including built-in plugins) may require some internal Hawtio ser
209209

210210
All these assumptions impact the way Hawtio code should be structured. Let's review various ways of _registering_ Hawtio plugins.
211211

212+
[#_static_synchronous_plugin_registration]
212213
==== Static, synchronous plugin registration
213214

214215
Let's assume a directory structure like this:
@@ -371,10 +372,13 @@ export const registerExample1Deferred: HawtioPlugin = () => {
371372
}
372373
----
373374

375+
This code passes an asynchronous function that returns a `Plugin`. We could also return an array of `Plugin` objects
376+
and Hawtio will register all of them. This is a good way for a plugin (represented by the `registerExample1Deferred` function) to register multiple Hawtio `Plugin` objects.
377+
374378
This code is correct with respect to following `hawtio.bootstrap()`:
375379

376380
* while the plugin is _evaluated_ asynchronously after `import()` finishes, Hawtio immediately know that there's `example1` plugin registered
377-
* `hawtio.bootstrap()` may be called immediately after `registerExample1Deferred()` and `bootstrap()` will internally wait for evaluating the deferred plugin
381+
* `hawtio.bootstrap()` may be called immediately after `registerExample1Deferred()` and `bootstrap()` will internally wait for evaluation of the deferred plugins
378382

379383
==== Using plugins with Module Federation
380384

@@ -413,7 +417,7 @@ _Static_ usage of Module Federation modules involves configuration of `webpack.c
413417

414418
https://github.com/hawtio/hawtio-next/tree/main/app[Hawtio React application] provides fully working example, but let's present the required configuration here. All JSON configuration is part of this object in Webpack configuration file:
415419

416-
[source,json]
420+
[source,javascript]
417421
----
418422
module.exports = (_, args) => {
419423
return [
@@ -431,7 +435,7 @@ module.exports = (_, args) => {
431435

432436
First, we need a declaration that there is (one or more) available _external provider of remote modules_:
433437

434-
[source,json]
438+
[source,javascript]
435439
----
436440
remotes: {
437441
'static-remotes': 'app@http://localhost:3000/hawtio/remoteEntry.js',
@@ -440,7 +444,7 @@ remotes: {
440444

441445
This is the _consuming_ part. This declaration should have a related counterpart in actual remote location, which is another `webpack.config.js` for a _remote container of remotely exposed modules_. The configuration of the _remote_ part looks like this:
442446

443-
[source,json]
447+
[source,javascript]
444448
----
445449
name: 'app',
446450
filename: 'remoteEntry.js',
@@ -488,7 +492,7 @@ These two module identifiers (`static-remotes/remote1` and `static-remotes/remot
488492

489493
To make life easier, we can tell IDE that these _special_ module locations are actually some real code locations. We can use this `tsconfig.json` configuration:
490494

491-
[source,json]
495+
[source,javascript]
492496
----
493497
{
494498
"compilerOptions": {

0 commit comments

Comments
 (0)