关于emitter、eventHub的使用场景
=======================

Emitter提供跨线程事件的发送和处理功能，包括事件的持续订阅、单次订阅、取消订阅及事件队列的发送。

1.  订阅事件
    
    import { emitter } from '@kit.BasicServicesKit'; 
     
    const TAG: string = 'ThreadModel';
    
    _// Define an event with an eventId of 1_
    let event: emitter.InnerEvent = {
      eventId: 1
    };
    
    _// Execute the callback after receiving an event with eventId 1_
    let callback = (eventData: emitter.EventData): void => {
      this.getUIContext().getPromptAction().showToast({
        message: JSON.stringify(eventData)
      });
    };
    
    _// Subscribe to events with eventId 1_
    emitter.on(event,callback);
    this.getUIContext().getPromptAction().showToast({
      message: 'subscribe\_success'
    });
    
2.  发送事件
    
    import { emitter } from '@kit.BasicServicesKit';
    
    _// Define an event with an eventId of 1 and a priority of Low_ 
    let event: emitter.InnerEvent = {
      eventId: 1,
      priority: emitter.EventPriority.LOW
    };
    
    let eventData: emitter.EventData = {
      data: {
        content: 'c',
        id: 1,
        isEmpty: false
      }
    };
    
    _// Send an event with eventId 1 and the event content is eventData_
    emitter.emit(event,eventData);
    
    EventHub提供同线程内事件的发送与处理功能，包括事件订阅、取消订阅及触发。以UIAbility组件与UI的数据同步为例，具体使用方法请参考相关文档。
    
    **参考链接**
    
    [UIAbility组件与UI的数据同步](https://developer.huawei.com/consumer/cn/doc/harmonyos-guides/uiability-data-sync-with-ui)