提交 d243e639 编写于 作者: E esterzhou

update doc

Signed-off-by: Nesterzhou <ester.zhou@huawei.com>
上级 e97fc035
......@@ -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.<br>**System capability**: SystemCapability.Notification.Emitter |
| HIGH | 1 | The event will be emitted before low-priority events.<br>**System capability**: SystemCapability.Notification.Emitter |
| LOW | 2 | The event will be emitted before idle-priority events. By default, an event is in LOW priority.<br>**System capability**: SystemCapability.Notification.Emitter|
| IDLE | 3 | The event will be emitted after all the other events.<br>**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.<br>**System capability**: SystemCapability.Notification.Emitter|
| priority | [EventPriority](#eventpriority) | Yes | Yes | Emit priority of the event.<br>**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.<br>**System capability**: SystemCapability.Notification.Emitter|
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册