Defining attributes of web components #3431
-
Hi everyone 🙂 I could not find a part in the documentation which talks about passing attributes to the web components registered in the Luigi config, which makes me believe that it is not possible. Am I missing something? I have also analysed the code concerning the creation of a web component node in the DOM and I see that Luigi sets only one attribute for its purposes. However there is no possibility to add more of them. Supporting this behaviour requires little modifications, in fact I have found a solution by changing the signature of the method responsible for the creation of the node. Is there a better approach or will there be? |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 4 replies
-
Hi @Lorenzo-Pappalardo , Thanks for the question. In your Luigi config you can have:
Then in myWebComponent.js you can retrieve the data through the context easily using our LuigiElement lifecycle methods:
Another way of creating webcomponent-based microfrontends would be to use luigi-container. Even though we are still working on it, and adding new features, you can have a look at the example test-app here.
Since it can be embedded on any part of your applications DOM, it allows for more flexibility, which might be what you are looking for. Here are some examples to play around with:
Let us know if you have further questions |
Beta Was this translation helpful? Give feedback.
-
Hi @ndricimrr, I understand that Luigi already has a way to pass data using context, however that ties the web component implementation to the Luigi-specific logic. That by itself is not necessarily a problem as long as the web component is intended for use just in Luigi. But I would like to have a web component that works also outside of it, so having the possibility to pass data to the web component using the standard approach (via attributes) is important to me. Also because I want to avoid having the Luigi client dependency in each web component. I think that supporting this use case would not require too many changes in the Luigi logic and would only be a new option available for developers. I will prepare a small PR as proof-of-concept with the changes needed, in my opinion, to enable this behaviour. |
Beta Was this translation helpful? Give feedback.
-
thanks for starting this interesting discussion. I know you mentioned that you have this use case, but I think it is not very common to have a micro frontend/standard reusable component hybrid. As there is a possibility to achieve what you need using a wrapper web component, I'd say there is no need to have that part of luigi core. IMHO this has even the advantage to keep your generic web component free from luigi-related code, if you may need some luigi client features in the future and just have that in the wrapper. But maybe I'm missing something, so feel free to disagree ;) |
Beta Was this translation helpful? Give feedback.
Hi @Lorenzo-Pappalardo,
I absolutely agree with your general statement, but still don't come to the conclusion that this particular topic is a common use-case.
Maybe this will change, and if we see a high demand, we will definitely consider to add it.
On the other hand I absolutely understand that you are not very happy with creating boiler-plate wrapper-webcomponents if they don't do anything but mapping key-values from one format to another. Therefore we have introduced a new feature that might be helpful in your scenario (and maybe also in others). Since v2.7.0 you can use the webcomponentCreationInterceptor to customize the web component element before it gets added to the DOM, simila…