UNPKG

ionic-framework

Version:

An advanced HTML5 mobile app framework built on Angular2

48 lines (47 loc) 1.46 kB
/** * @name Events * @description * Events is a pub/sub style event system for sending and responding to application-level * events across your app. * @usage * ```ts * // first page (publish an event when a user is created) * function createUser(user) { * console.log('User created!') * events.publish('user:created', user); * } * * // second page (listen for the user created event) * events.subscribe('user:created', (user) => { * console.log('Welcome', user); * }); * * ``` * @demo /docs/v2/demos/events/ */ export declare class Events { private _channels; /** * Subscribe to an event topic. Events that get posted to that topic will trigger the provided handler. * * @param {string} topic the topic to subscribe to * @param {function} handler the event handler */ subscribe(topic: any, ...handlers: any[]): void; /** * Unsubscribe from the given topic. Your handler will no longer receive events published to this topic. * * @param {string} topic the topic to unsubscribe from * @param {function} handler the event handler * * @return true if a handler was removed */ unsubscribe(topic: any, handler: any): boolean; /** * Publish an event to the given topic. * * @param {string} topic the topic to publish to * @param {any} eventData the data to send as the event */ publish(topic: any, ...args: any[]): any[]; }