ArcGIS for Developers

Message action

Message/action is a way to support communication between widget to widget, widget to framework, and framework to widget. To learn about the message/action concept, see core concepts.

Publishing a message

A widget calls MessageManager.getInstance().publishMessage(message) to publish a message. For example, the List widget publishes the DataRecordsSelectionChange message when a list item is clicked or a Map widget publishes the ExtentChange message when the view is changed, which updates the List widget content. The following MessageTypes are supported:

  • StringSelectionChange
  • ExtentChange
  • DataRecordsSelectionChange
  • DataRecordSetCreate
  • DataRecordSetUpdate

To publish a message, a widget should declare the published messages in the manifest.json file.

   
  "publishMessages": [
    "DATA_RECORDS_SELECTION_CHANGE"
  ]

Creating a message action

To create a message action, you will need to extend AbstractMessageAction class. There are several methods and functions that help with developing message actions.

The filterMessageType method is used to filter the available actions.

     
export default class QueryAction extends AbstractMessageAction{
  filterMessageType(messageType: MessageType, messageWidgetId?: string): boolean{
    return [MessageType.StringSelectionChange, MessageType.DataRecordsSelectionChange].indexOf(messageType) > -1;
  }
}

filterMessage method is used to filter messages in message manager.

   
filterMessage(message: Message): boolean{
    return true;
  }

The getSettingComponentUri component can be used to configure the action based on the message.

   
getSettingComponentUri(messageType: MessageType, messageWidgetId?: string): string {
    return 'actions/query-action-setting';
  }

onExecute method handles the logic for what you would like to happen for your message type. In the snippet below, it basically selects the action based on the message type and sends it from the application to the store using getAppStore() function using the dispatch property. This dispatches the redux action and allows the state to be updated. Learn more about redux actions and using the store in Redux.

              
onExecute(message: Message, actionConfig?: any): Promise<boolean> | boolean{
    let q = `${(actionConfig as ConfigForStringChangeMessage).fieldName} = '${message}'`
    switch(message.type){
      case MessageType.StringSelectionChange:
        q = `${(actionConfig as ConfigForStringChangeMessage).fieldName} = '${(message as StringSelectionChangeMessage).str}'`
        break;
      case MessageType.DataRecordsSelectionChange:
        q = `${(actionConfig as ConfigForFeatureChangeMessage).queryFieldName} =
        '${(message as DataRecordsSelectionChangeMessage).records[0].getData()[(actionConfig as ConfigForFeatureChangeMessage).featureFieldName]}'`
        break;
    }
    getAppStore().dispatch(appActions.widgetStatePropChange(this.widgetId, 'queryString', q));
    return true;
}