mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2026-03-13 10:22:08 +08:00
Comments
This commit is contained in:
@@ -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(() => {
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user