未验证 提交 b6dd8c59 编写于 作者: O openharmony_ci 提交者: Gitee

!10830 翻译完成 9357/10216/10047

Merge pull request !10830 from ester.zhou/TR-9357
......@@ -32,7 +32,8 @@ import commonEvent from '@ohos.commonEvent';
2. Create a **subscribeInfo** object. For details about the data types and parameters of the object, see [CommonEventSubscribeInfo](../reference/apis/js-apis-commonEvent.md#commoneventsubscribeinfo).
```js
private subscriber = null // Used to save the created subscriber object for subsequent subscription and unsubscription.
// Used to save the created subscriber object for subsequent subscription and unsubscription.
private subscriber = null
// Subscriber information
var subscribeInfo = {
......
# Common Event and Notification Overview
The common event and notification module enables applications to publish messages to other applications, and receive messages from the system or other applications. These messages can be news push messages, advertisement notifications, or warning information.
The common event and notification module enables applications to publish messages to other applications, and receive messages from the system or other applications. These messages can be news push messages, advertisement notifications, warning information, and more.
Common Event Service (CES) enables applications to publish, subscribe to, and unsubscribe from common events. Based on the sender type, common events are classified into system common events and custom common events.
......
......@@ -16,19 +16,6 @@ import emitter from '@ohos.events.emitter'
None
## EventPriority
Enumerates the event emit priority levels.
**System capability**: SystemCapability.Notification.Emitter
| 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. |
## emitter.on
on(event: [InnerEvent](#innerevent), callback: Callback\<[EventData](#eventdata)\>): void
......@@ -39,21 +26,21 @@ Subscribes to an event in persistent manner. This API uses a callback to return
**Parameters**
| 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.|
| Name | Type | Mandatory| Description |
| -------- | ----------------------------------- | ---- | --------------------------------------- |
| event | [InnerEvent](#innerevent) | Yes | Event to subscribe to in persistent manner. The **EventPriority** settings do not take effect.|
| callback | Callback\<[EventData](#eventdata)\> | Yes | Callback used to return the event. |
**Example**
```javascript
var innerEvent = {
let innerEvent = {
eventId: 1
};
var callback = (eventData) => {
function EmitterCallback(eventData) {
console.info('callback');
};
emitter.on(innerEvent, callback);
}
emitter.on(innerEvent, EmitterCallback);
```
## emitter.once
......@@ -66,21 +53,21 @@ Subscribes to an event in one-shot manner and unsubscribes from it after the eve
**Parameters**
| 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.|
| Name | Type | Mandatory| Description |
| -------- | ----------------------------------- | ---- | --------------------------------------- |
| event | [InnerEvent](#innerevent) | Yes | Event to subscribe to in one-shot manner. The **EventPriority** settings do not take effect.|
| callback | Callback\<[EventData](#eventdata)\> | Yes | Callback used to return the event. |
**Example**
```javascript
var innerEvent = {
let innerEvent = {
eventId: 1
};
var callback = (eventData) => {
function EmitterCallback(eventData) {
console.info('once callback');
};
emitter.once(innerEvent, callback);
emitter.once(innerEvent, EmitterCallback);
```
## emitter.off
......@@ -121,18 +108,31 @@ Emits an event to the event queue.
**Example**
```javascript
var eventData = {
let eventData = {
data: {
"content": "c",
"id": 1,
}};
var innerEvent = {
let innerEvent = {
eventId: 1,
priority: emitter.EventPriority.HIGH
};
emitter.emit(innerEvent, eventData);
```
## EventPriority
Enumerates the event emit priority levels.
**System capability**: SystemCapability.Notification.Emitter
| 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. |
## InnerEvent
Describes an in-process event.
......@@ -141,7 +141,7 @@ Describes an in-process event.
| Name | Type | Readable| Writable| Description |
| -------- | ------------------------------- | ---- | ---- | ---------------------------------- |
| eventId | number | Yes | Yes | Event ID, which is used to identify an event.|
| eventId | number | Yes | Yes | Event ID.|
| priority | [EventPriority](#eventpriority) | Yes | Yes | Emit priority of the event. |
## EventData
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册