diff --git a/demos/native/index.ts b/demos/native/index.ts index 2024c45e7b..4512d43387 100644 --- a/demos/native/index.ts +++ b/demos/native/index.ts @@ -27,13 +27,17 @@ class MyApp { events.subscribe('user:created', (user) => { console.log('User created', user); + return { + what: 'what' + } }) setInterval(() => { - events.publish('user:created', { + var results = events.publish('user:created', { name: 'Max Lynch', id: 1 }) + console.log('Got results', results); }, 2000); setTimeout(() => { diff --git a/ionic/util/events.ts b/ionic/util/events.ts index f5c7db39bd..215f283f66 100644 --- a/ionic/util/events.ts +++ b/ionic/util/events.ts @@ -1,13 +1,12 @@ import {Injectable} from 'angular2/angular2'; /** - * Event is a pub/sub style event system for sending and responding to application-level + * Events is a pub/sub style event system for sending and responding to application-level * events across your app. */ @Injectable() export class Events { constructor() { - console.log('Events constructed'); this.channels = []; } @@ -33,13 +32,17 @@ export class Events { * * @param topic the topic to unsubscribe from * @param handler the event handler + * + * @return true if a handler was removed */ unsubscribe(topic, handler) { - var t = this.channels[topic]; + let t = this.channels[topic]; if(!t) { - return null; + return false; } + let i = t.indexOf(handler); + t.splice(t.indexOf(handler), 1); // If the channel is empty now, remove it from the channel map