diff --git a/en/application-dev/reference/apis/js-apis-emitter.md b/en/application-dev/reference/apis/js-apis-emitter.md index bb6ff52a02fb33d938f8432b3864185b6b0778d2..8e08290aaefa6b8f52eec4f21f4671b1099d92fc 100644 --- a/en/application-dev/reference/apis/js-apis-emitter.md +++ b/en/application-dev/reference/apis/js-apis-emitter.md @@ -8,12 +8,6 @@ import emitter from '@ohos.events.emitter' ``` -## System Capabilities - -```javascript -SystemCapability.Notification.Emitter -``` - ## Required Permissions None @@ -22,25 +16,27 @@ None Enumerates the event emit priority levels. -| Name| Value| Description| +| Name | Value | Description | | --------- | ---- | ------------------------------------------------- | -| IMMEDIATE | 0 | The event will be emitted immediately.| -| HIGH | 1 | The event will be emitted before low-priority events.| -| LOW | 2 | The event will be emitted before idle-priority events. By default, an event is in LOW priority.| -| IDLE | 3 | The event will be emitted after all the other events.| +| IMMEDIATE | 0 | The event will be emitted immediately.
**System capability**: SystemCapability.Notification.Emitter | +| HIGH | 1 | The event will be emitted before low-priority events.
**System capability**: SystemCapability.Notification.Emitter | +| LOW | 2 | The event will be emitted before idle-priority events. By default, an event is in LOW priority.
**System capability**: SystemCapability.Notification.Emitter| +| IDLE | 3 | The event will be emitted after all the other events.
**System capability**: SystemCapability.Notification.Emitter | ## emitter.on on(event: [InnerEvent](#innerevent), callback: Callback\<[EventData](#eventdata)\>): void -Subscribes to an event in persistent manner. This method uses a callback to return the event. +Subscribes to an event in persistent manner. This API uses a callback to return the event. + +**System capability**: SystemCapability.Notification.Emitter **Parameters** -| Name| Type| Mandatory| Description| +| Name | Type | Mandatory| Description | | -------- | ----------------------------------- | ---- | ------------------------ | -| event | [InnerEvent](#innerevent) | Yes| Event to subscribe to in persistent manner.| -| callback | Callback\<[EventData](#eventdata)\> | Yes| Callback used to return the event.| +| event | [InnerEvent](#innerevent) | Yes | Event to subscribe to in persistent manner. | +| callback | Callback\<[EventData](#eventdata)\> | Yes | Callback used to return the event.| **Example** @@ -56,16 +52,18 @@ emitter.on(innerEvent, callback); ## emitter.once -once(event: [InnerEvent](#innerevent), callback: Callback\<[EventData](#eventdata)\>): **void** +once(event: [InnerEvent](#innerevent), callback: Callback\<[EventData](#eventdata)\>): void Subscribes to an event in one-shot manner and unsubscribes from it after the event callback is received. +**System capability**: SystemCapability.Notification.Emitter + **Parameters** -| Name| Type| Mandatory| Description| +| Name | Type | Mandatory| Description | | -------- | ----------------------------------- | ---- | ------------------------ | -| event | [InnerEvent](#innerevent) | Yes| Event to subscribe to in one-shot manner.| -| callback | Callback\<[EventData](#eventdata)\> | Yes| Callback used to return the event.| +| event | [InnerEvent](#innerevent) | Yes | Event to subscribe to in one-shot manner. | +| callback | Callback\<[EventData](#eventdata)\> | Yes | Callback used to return the event.| **Example** @@ -85,11 +83,13 @@ off(eventId: number): void Unsubscribes from an event. +**System capability**: SystemCapability.Notification.Emitter + **Parameters** -| Name| Type| Mandatory| Description| -| ------- | ------ | ---- | -------------- | -| eventId | number | Yes| Event ID.| +| Name | Type | Mandatory| Description | +| ------- | ------ | ---- | ------ | +| eventId | number | Yes | Event ID.| **Example** @@ -103,19 +103,21 @@ emit(event: InnerEvent, data?: EventData): void Emits an event to the event queue. +**System capability**: SystemCapability.Notification.Emitter + **Parameters** -| Name| Type| Mandatory| Description| +| Name| Type | Mandatory| Description | | ------ | ------------------------- | ---- | -------------- | -| event | [InnerEvent](#innerevent) | Yes| Event to emit.| -| data | [EventData](#eventdata) | No| Data carried by the event.| +| event | [InnerEvent](#innerevent) | Yes | Event to emit. | +| data | [EventData](#eventdata) | No | Data carried by the event.| **Example** ```javascript var eventData = { data: { - 'content': "c", + "content": "c", "id": 1, }}; var innerEvent = { @@ -129,15 +131,15 @@ emitter.emit(innerEvent, eventData); Describes an intra-process event. -| Name| Type| Readable| Writable| Description| +| Name | Type | Readable| Writable| Description | | -------- | ------------------------------- | ---- | ---- | ---------------------------------- | -| eventId | number | Yes| Yes| Event ID, which is used to identify an event.| -| priority | [EventPriority](#eventpriority) | Yes| Yes| Emit priority of the event.| +| eventId | number | Yes | Yes | Event ID, which is used to identify an event.
**System capability**: SystemCapability.Notification.Emitter| +| priority | [EventPriority](#eventpriority) | Yes | Yes | Emit priority of the event.
**System capability**: SystemCapability.Notification.Emitter | ## EventData Describes the data passed in the event. -| Name| Type| Readable| Writable| Description| +| Name| Type | Readable| Writable| Description | | ---- | ------------------ | ---- | ---- | -------------- | -| data | [key: string]: any | Yes| Yes| Data carried by the event.| +| data | [key: string]: any | Yes | Yes | Data carried by the event. The data type can be String, Integer, or Boolean.
**System capability**: SystemCapability.Notification.Emitter|