UNPKG

2.09 kBTypeScriptView Raw
1import { DomController } from '../platform/dom-controller';
2import { Platform } from '../platform/platform';
3/**
4 * @name Events
5 * @description
6 * Events is a publish-subscribe style event system for sending and responding to application-level
7 * events across your app.
8 *
9 * @usage
10 * ```ts
11 * import { Events } from 'ionic-angular';
12 *
13 * // first page (publish an event when a user is created)
14 * constructor(public events: Events) { }
15 *
16 * createUser(user) {
17 * console.log('User created!')
18 * this.events.publish('user:created', user, Date.now());
19 * }
20 *
21 *
22 * // second page (listen for the user created event after function is called)
23 * constructor(public events: Events) {
24 * events.subscribe('user:created', (user, time) => {
25 * // user and time are the same arguments passed in `events.publish(user, time)`
26 * console.log('Welcome', user, 'at', time);
27 * });
28 * }
29 *
30 * ```
31 * @demo /docs/demos/src/events/
32 */
33export declare class Events {
34 private _channels;
35 /**
36 * Subscribe to an event topic. Events that get posted to that topic will trigger the provided handler.
37 *
38 * @param {string} topic the topic to subscribe to
39 * @param {function} handler the event handler
40 */
41 subscribe(topic: string, ...handlers: Function[]): void;
42 /**
43 * Unsubscribe from the given topic. Your handler will no longer receive events published to this topic.
44 *
45 * @param {string} topic the topic to unsubscribe from
46 * @param {function} handler the event handler
47 *
48 * @return true if a handler was removed
49 */
50 unsubscribe(topic: string, handler?: Function): boolean;
51 /**
52 * Publish an event to the given topic.
53 *
54 * @param {string} topic the topic to publish to
55 * @param {any} eventData the data to send as the event
56 */
57 publish(topic: string, ...args: any[]): any[];
58}
59/**
60 * @hidden
61 */
62export declare function setupEvents(plt: Platform, dom: DomController): Events;
63/**
64 * @hidden
65 */
66export declare function setupProvideEvents(plt: Platform, dom: DomController): () => Events;