• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2021-2023 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 '../@ohos.base';
17
18/**
19 * The event center of a context, support the subscription and publication of events.
20 *
21 * @syscap SystemCapability.Ability.AbilityRuntime.Core
22 * @StageModelOnly
23 * @since 9
24 */
25/**
26 * The event center of a context, support the subscription and publication of events.
27 *
28 * @syscap SystemCapability.Ability.AbilityRuntime.Core
29 * @StageModelOnly
30 * @atomicservice
31 * @since 11
32 */
33export default class EventHub {
34  /**
35   * Subscribe to an event.
36   *
37   * @param { string } event - Indicates the event.
38   * @param { Function } callback - Indicates the callback.
39   * @throws { BusinessError } 401 - If the input parameter is not valid parameter.
40   * @syscap SystemCapability.Ability.AbilityRuntime.Core
41   * @StageModelOnly
42   * @since 9
43   */
44  /**
45   * Subscribe to an event.
46   *
47   * @param { string } event - Indicates the event.
48   * @param { Function } callback - Indicates the callback.
49   * @throws { BusinessError } 401 - If the input parameter is not valid parameter.
50   * @syscap SystemCapability.Ability.AbilityRuntime.Core
51   * @StageModelOnly
52   * @atomicservice
53   * @since 11
54   */
55  on(event: string, callback: Function): void;
56
57  /**
58   * Unsubscribe from an event.
59   *
60   * @param { string } event - Indicates the event.
61   * @param { Function } [callback] - Indicates the callback.
62   * @throws { BusinessError } 401 - If the input parameter is not valid parameter.
63   * @syscap SystemCapability.Ability.AbilityRuntime.Core
64   * @StageModelOnly
65   * @since 9
66   */
67  /**
68   * Unsubscribe from an event.
69   *
70   * @param { string } event - Indicates the event.
71   * @param { Function } [callback] - Indicates the callback.
72   * @throws { BusinessError } 401 - If the input parameter is not valid parameter.
73   * @syscap SystemCapability.Ability.AbilityRuntime.Core
74   * @StageModelOnly
75   * @atomicservice
76   * @since 11
77   */
78  off(event: string, callback?: Function): void;
79
80  /**
81   * Trigger the event callbacks.
82   *
83   * @param { string } event - Indicates the event.
84   * @param { Object[] } args - Indicates the callback arguments.
85   * @throws { BusinessError } 401 - If the input parameter is not valid parameter.
86   * @syscap SystemCapability.Ability.AbilityRuntime.Core
87   * @StageModelOnly
88   * @since 9
89   */
90  /**
91   * Trigger the event callbacks.
92   *
93   * @param { string } event - Indicates the event.
94   * @param { Object[] } args - Indicates the callback arguments.
95   * @throws { BusinessError } 401 - If the input parameter is not valid parameter.
96   * @syscap SystemCapability.Ability.AbilityRuntime.Core
97   * @StageModelOnly
98   * @atomicservice
99   * @since 11
100   */
101  emit(event: string, ...args: Object[]): void;
102}
103