1/* 2 * Copyright (c) 2021-2022 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"), 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16import { BusinessError } from '../basic'; 17 18/** 19 * The event center of a context, support the subscription and publication of events. 20 * @syscap SystemCapability.Ability.AbilityRuntime.Core 21 * @StageModelOnly 22 * @since 9 23 */ 24export default class EventHub { 25 /** 26 * Subscribe to an event. 27 * @param { string } event - Indicates the event. 28 * @param { Function } callback - Indicates the callback. 29 * @throws { BusinessError } 401 - If the input parameter is not valid parameter. 30 * @syscap SystemCapability.Ability.AbilityRuntime.Core 31 * @StageModelOnly 32 * @since 9 33 */ 34 on(event: string, callback: Function): void 35 36 /** 37 * Unsubscribe from an event. 38 * @param { string } event - Indicates the event. 39 * @param { Function } callback - Indicates the callback. 40 * @throws { BusinessError } 401 - If the input parameter is not valid parameter. 41 * @syscap SystemCapability.Ability.AbilityRuntime.Core 42 * @StageModelOnly 43 * @since 9 44 */ 45 off(event: string, callback?: Function): void 46 47 /** 48 * Trigger the event callbacks. 49 * @param { string } event - Indicates the event. 50 * @param { Object[] } args - Indicates the callback arguments. 51 * @throws { BusinessError } 401 - If the input parameter is not valid parameter. 52 * @syscap SystemCapability.Ability.AbilityRuntime.Core 53 * @StageModelOnly 54 * @since 9 55 */ 56 emit(event: string, ...args: Object[]): void 57}