Added un-subscribe event and covered the Events-module

This commit is contained in:
Christoph Oberhofer
2014-12-19 13:18:47 +01:00
parent 480e962ea8
commit c44889f599
2 changed files with 131 additions and 0 deletions
+20
View File
@@ -15,6 +15,10 @@ define(function() {
}
return events[eventName];
}
function clearEvents(){
events = {};
}
function publishSubscription(subscription, data) {
if (subscription.async) {
@@ -63,6 +67,22 @@ define(function() {
async: async,
once: true
});
},
unsubscribe: function(eventName, callback) {
var event;
if (eventName) {
event = getEvent(eventName);
if (event && callback) {
event.subscribers = event.subscribers.filter(function(subscriber){
return subscriber.callback !== callback;
});
} else {
event.subscribers = [];
}
} else {
clearEvents();
}
}
};
}();