!230 add emitter.d.ts

Merge pull request !230 from zengsiyu/dev
This commit is contained in:
openharmony_ci 2021-12-24 10:04:14 +00:00 committed by Gitee
commit fde975e34b

117
api/@ohos.emitter.d.ts vendored Normal file
View File

@ -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<EventData>): 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<EventData>): 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;