@luigi-project/client-support-angular 2.3.0-rc2 → 2.3.0-rc3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +73 -35
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
# ClientSupportAngular
|
|
2
2
|
|
|
3
|
-
This library provides several features to run your Angular application inside the Luigi micro frontend framework.
|
|
3
|
+
This library provides several features which make it easier to run your Angular application inside the Luigi micro frontend framework.
|
|
4
4
|
If you want to know more about Luigi, please have a look at the [Luigi homepage](https://luigi-project.io/).
|
|
5
5
|
|
|
6
6
|
## How to use the library
|
|
7
|
+
|
|
7
8
|
1. Import the library in the `package.json`:
|
|
8
9
|
```javascript
|
|
9
10
|
npm install @luigi-project/client-support-angular -s
|
|
@@ -19,27 +20,35 @@ imports: [
|
|
|
19
20
|
```
|
|
20
21
|
|
|
21
22
|
## Features
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
* [
|
|
23
|
+
|
|
24
|
+
These are the features provided by the library:
|
|
25
|
+
* [LuigiContextService](#LuigiContextService) - allows you to observe context changes in Luigi.
|
|
26
|
+
* [Preload component](#preload-component) - an empty Angular component that can be used to build a preload route. See also [preloadUrl](https://docs.luigi-project.io/docs/navigation-parameters-reference/?section=viewgroupsettings).
|
|
27
|
+
* [LuigiAutoRoutingService](#LuigiAutoRoutingService) - enables the synchronization of Angular routes with Luigi. It contains the following elements:
|
|
28
|
+
* [LuigiRouteStrategy](#LuigiRouteStrategy) - Luigi's implementation of an Angular [RouteReuseStrategy](https://angular.io/api/router/RouteReuseStrategy).
|
|
29
|
+
* [AutoRouting for modals](#autorouting-for-modals) - synchronizes Angular modals with Luigi.
|
|
30
|
+
* [LuigiMockModule](#LuigiMockModule) - an Angular module that listens to Luigi Client calls and messages and sends a mocked response back. See also [LuigiMockUtil](https://docs.luigi-project.io/docs/luigi-testing-utilities).
|
|
31
|
+
|
|
25
32
|
|
|
26
33
|
### LuigiContextService
|
|
34
|
+
|
|
27
35
|
You can inject this service inside your Angular items in order to:
|
|
28
|
-
* Get the current (latest)
|
|
29
|
-
* Provide an Observable<Context
|
|
30
|
-
|
|
31
|
-
**LuigiContextService** is an abstract class. Its implementation is in the **LuigiContextServiceImpl** class.
|
|
36
|
+
* Get the current (latest) [context](https://docs.luigi-project.io/docs/navigation-advanced?section=contexts) that we received from Luigi Core
|
|
37
|
+
* Provide an `Observable<Context>` where through subscribing, you can get any context change
|
|
38
|
+
|
|
39
|
+
**LuigiContextService** is an abstract class. Its implementation is in the **LuigiContextServiceImpl** class.
|
|
32
40
|
If you need to change or extend the implementation, you can easily create a new class extending **LuigiContextServiceImpl**:
|
|
33
41
|
|
|
34
|
-
In this class, we added the possibility to "reuse" a component and not initialize it every time you load it (it could be useful to keep component state.)
|
|
42
|
+
In this class, we added the possibility to "reuse" a component and not initialize it every time you load it (as it could be useful to keep component state.)
|
|
35
43
|
|
|
36
44
|
```javascript
|
|
37
45
|
export class YourContextService extends LuigiContextServiceImpl {
|
|
38
|
-
....
|
|
46
|
+
....
|
|
39
47
|
}
|
|
40
48
|
|
|
41
49
|
```
|
|
42
50
|
Inside your module, redefine the provider:
|
|
51
|
+
|
|
43
52
|
```javascript
|
|
44
53
|
providers: [
|
|
45
54
|
{
|
|
@@ -48,30 +57,50 @@ providers: [
|
|
|
48
57
|
}
|
|
49
58
|
]
|
|
50
59
|
```
|
|
51
|
-
|
|
60
|
+
|
|
52
61
|
### LuigiAutoRoutingService
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
62
|
+
|
|
63
|
+
This service cannot be used directly, but it provides useful features on how to synchronize your Angular application with Luigi navigation.
|
|
64
|
+
|
|
65
|
+
For example, when the user navigates through different pages within a micro frontend, you can use this feature to update Luigi accordingly. (You can also find more information about this process in the [micro frontend routing](https://docs.luigi-project.io/docs/microfrontend-routing) document.)
|
|
66
|
+
|
|
67
|
+
### Preload component
|
|
68
|
+
|
|
69
|
+
In your Angular route configuration, you can add in any of the following preload components:
|
|
56
70
|
|
|
57
71
|
```javascript
|
|
58
72
|
{path: 'luigi-client-support-preload',component: Sample1Component,data: { fromVirtualTreeRoot: true }}
|
|
59
73
|
{path: 'luigi-client-support-preload',component: Sample2Component,data: { luigiRoute: '/home/sample2' }}
|
|
74
|
+
{path: 'luigi-client-support-preload',component: Sample2Component,data: { luigiRoute: '/home/sample2', fromContext: true}}
|
|
75
|
+
{path: 'luigi-client-support-preload',component: Sample2Component,data: { luigiRoute: '/home/sample2', fromContext: 'localContext'}}
|
|
60
76
|
```
|
|
61
77
|
|
|
62
|
-
|
|
78
|
+
Under the hood, these components make use of Luigi's [linkManager](https://docs.luigi-project.io/docs/luigi-client-api?section=linkmanager) in the following way:
|
|
79
|
+
|
|
80
|
+
For `data: { fromVirtualTreeRoot: true }`, once we load Sample1Component, this Luigi Client API method is called:
|
|
63
81
|
```javascript
|
|
64
82
|
luigiClient.linkManager().fromVirtualTreeRoot().withoutSync().navigate({route url});
|
|
65
83
|
```
|
|
66
|
-
|
|
84
|
+
|
|
85
|
+
For `data: { luigiRoute: '/home/sample2' }`, this Luigi Client API method is called:
|
|
67
86
|
```javascript
|
|
68
87
|
luigiClient.linkManager().withoutSync().navigate(data.luigiRoute);
|
|
69
88
|
```
|
|
70
|
-
|
|
89
|
+
|
|
90
|
+
For `data: { luigiRoute: '/home/sample2', fromContext: true }`, this Luigi Client API method is called:
|
|
91
|
+
```javascript
|
|
92
|
+
luigiClient.linkManager().fromClosestContext().withoutSync().navigate(data.luigiRoute);
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
For `data: { luigiRoute: '/home/sample2', fromContext: 'localContext' }`, this Luigi Client API method is called:
|
|
96
|
+
```javascript
|
|
97
|
+
luigiClient.linkManager().fromContext('localContext').withoutSync().navigate(data.luigiRoute);
|
|
98
|
+
```
|
|
71
99
|
|
|
72
100
|
|
|
73
|
-
|
|
74
|
-
|
|
101
|
+
### LuigiRouteStrategy
|
|
102
|
+
|
|
103
|
+
To use **LuigiAutoRoutingService**, this library defines a new **RouteReuseStrategy** named **LuigiRouteStrategy**.
|
|
75
104
|
If you need to define your own **RouteReuseStrategy**, you can extend **LuigiRouteStrategy** by overriding it in this way:
|
|
76
105
|
|
|
77
106
|
```javascript
|
|
@@ -92,22 +121,6 @@ and define the provider:
|
|
|
92
121
|
}
|
|
93
122
|
```
|
|
94
123
|
|
|
95
|
-
We also provide an example of how to extend **LuigiRouteStrategy** in class **LuigiReuseRouteStrategy**.
|
|
96
|
-
In this class, we added the possibility to "reuse" a component and not initialize it every time you load it (it could be useful to keep component state.)
|
|
97
|
-
|
|
98
|
-
**LuigiReuseRouteStrategy** can be configured in the following way:
|
|
99
|
-
```javascript
|
|
100
|
-
{path: 'luigi-client-support-preload',component: Sample1Component,data: { reuse: true }}
|
|
101
|
-
```
|
|
102
|
-
|
|
103
|
-
If you want to use **LuigiReuseRouteStrategy** (it is not enabled by default), you need to configure in your application:
|
|
104
|
-
```javascript
|
|
105
|
-
{
|
|
106
|
-
provide: RouteReuseStrategy,
|
|
107
|
-
useClass: LuigiReuseRouteStrategy
|
|
108
|
-
}
|
|
109
|
-
```
|
|
110
|
-
|
|
111
124
|
### AutoRouting for modals
|
|
112
125
|
|
|
113
126
|
Similarly to other components, modals which have a [modalPathParam](https://docs.luigi-project.io/docs/navigation-parameters-reference/?section=modalpathparam) can trigger a change in the URL when navigation occurs. In the Angular router of your Luigi app, you can enable auto-routing for modals using these parameters:
|
|
@@ -122,3 +135,28 @@ For example:
|
|
|
122
135
|
data: { updateModalDataPath: true, addHistoryEntry: true }
|
|
123
136
|
}
|
|
124
137
|
```
|
|
138
|
+
|
|
139
|
+
### LuigiMockModule
|
|
140
|
+
|
|
141
|
+
In the normal Luigi workflow, messages coming from Luigi Client to Luigi Core are processed on the Core and a proper response is sent back. However, in many systems where testing of micro frontends standalone is a necessity, the absence of Luigi Core to send back needed responses to Client micro frontends becomes a case of high coupling. To remove this coupling, we introduce **LuigiMockModule** for **Angular** applications. This module is attached to the start of your application where it intercepts all the Client calls and sends a mocked Core response back. This enables users to test their micro frontends standalone without depending on the Core.
|
|
142
|
+
To use **LuigiMockModule**, simply add it to the list of imports of your applications entry point. A good practice is to include it in the main testing module of your application as given in the example below:
|
|
143
|
+
|
|
144
|
+
```javascript
|
|
145
|
+
import {LuigiMockModule} from '@luigi-project/client-support-angular';
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* This module is used to run the application for e2e tests.
|
|
149
|
+
*/
|
|
150
|
+
@NgModule({
|
|
151
|
+
imports: [
|
|
152
|
+
AppModule,
|
|
153
|
+
LuigiMockModule,
|
|
154
|
+
],
|
|
155
|
+
bootstrap: [AppComponent]
|
|
156
|
+
})
|
|
157
|
+
export class AppTestingModule {}
|
|
158
|
+
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
To make mocking of Luigi Core easier, you can use a range of utility functions and assertions. Our lightweight [Luigi Testing Utilities](https://docs.luigi-project.io/docs/luigi-testing-utilities) library provides the necessary basic utility functions needed for your application.
|
|
162
|
+
|
package/package.json
CHANGED
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
"publishConfig": {
|
|
19
19
|
"tag": "client-support-angular"
|
|
20
20
|
},
|
|
21
|
-
"version": "2.3.0-
|
|
21
|
+
"version": "2.3.0-rc3",
|
|
22
22
|
"module": "fesm2015/luigi-project-client-support-angular.mjs",
|
|
23
23
|
"es2020": "fesm2020/luigi-project-client-support-angular.mjs",
|
|
24
24
|
"esm2020": "esm2020/luigi-project-client-support-angular.mjs",
|