From 5e9bd8acef670da4198be1e714ae99f7bdf943b5 Mon Sep 17 00:00:00 2001 From: zengsiyu Date: Fri, 24 Dec 2021 15:50:18 +0800 Subject: [PATCH] add emitter.d.ts Signed-off-by: zengsiyu Change-Id: I3f66c19d063cc5628cd1356aa8796e2fedca74a0 --- api/@ohos.emitter.d.ts | 117 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 117 insertions(+) create mode 100644 api/@ohos.emitter.d.ts diff --git a/api/@ohos.emitter.d.ts b/api/@ohos.emitter.d.ts new file mode 100644 index 0000000000..ac359eb225 --- /dev/null +++ b/api/@ohos.emitter.d.ts @@ -0,0 +1,117 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { Callback } from './basic'; + +/** + * Provides methods for sending and processing in-process events. + * + * @since 7 + * @import import events_emitter from '@ohos.emitter'; + * @permission N/A + */ +declare namespace emitter { + /** + * Subscribes to a certain event in persistent manner and receives the event callback. + * + * @since 7 + * @param event indicate event to subscribe to. + * @param callback indicate callback used to receive the event. + * @return - + */ + function on(event: InnerEvent, callback: Callback): void; + + /** + * Subscribes to a certain event in one-shot manner and unsubscribes from it + * after the event callback is received. + * + * @since 7 + * @param event indicate event to subscribe to in one shot. + * @param callback indicate callback used to receive the event. + * @return - + */ + function once(event: InnerEvent, callback: Callback): void; + + /** + * Unsubscribes from an event. + * + * @since 7 + * @param eventId indicate ID of the event to unsubscribe from. + * @return - + */ + function off(eventId: number): void; + + /** + * Emits an event to the event queue. + * + * @since 7 + * @param event indicate event to emit. + * @param data indicate data carried by the event. + * @return - + */ + function emit(event: InnerEvent, data?: EventData): void; + + /** + * Describes data passed in the event. + */ + export interface EventData { + /** + * Data carried by the event. + */ + data?: {[key: string]: any}; + } + + /** + * Describes an intra-process event. + */ + export interface InnerEvent { + /** + * Event ID, which is used to identify an event. + */ + eventId: number; + + /** + * Emit priority of the event. The default priority is {@link EventPriority.LOW}. + */ + priority?: EventPriority; + } + + /** + * Indicates the emit priority of the event. + */ + export enum EventPriority { + /** + * Indicates that the event will be emitted immediately. + */ + IMMEDIATE = 0, + + /** + * Indicates that the event will be emitted before low-priority events. + */ + HIGH, + + /** + * Indicates that the event will be emitted before idle-priority events. By default, an event is in LOW priority. + */ + LOW, + + /** + * Indicates that the event will be emitted after all the other events. + */ + IDLE, + } +} + +export default emitter; \ No newline at end of file -- Gitee