Why define lightningMessageFields in Lightning Message Service?

195 views Asked by At

I am wondering something. In the XML file of a lightning message channel I can specify lightningMessageFields or I can omit this. Either way messages on the channel function correctly whatever you put into them. Example one with no fields:

<LightningMessageChannel xmlns="http://soap.sforce.com/2006/04/metadata">
    <masterLabel>TestChannel</masterLabel>
    <isExposed>true</isExposed>
    <description></description>
</LightningMessageChannel>

If i create a payload like this, it works:

let message = {request: true};
publish(this.context, TESTCHANNEL, message);

Example two with a field called 'success':

<LightningMessageChannel xmlns="http://soap.sforce.com/2006/04/metadata">
        <masterLabel>TestChannel</masterLabel>
        <isExposed>true</isExposed>
        <description></description>
        <lightningMessageFields>
               <fieldName>success</fieldName>
        <description></description>
    </lightningMessageFields>
</LightningMessageChannel>

The same payload still works:

let message = {request: true};
publish(this.context, TESTCHANNEL, message);

So why bother with fields? If any one has any insight into this, Id be very interested. Thanks. Dane

1

There are 1 answers

0
Andres Perez On

I like putting the messages there, but just for documentation, as you know it works either way. But if you need to remember the data that was supposed to be passed or received, then this will be very helpful.