mirror of
https://github.com/serratus/quaggaJS.git
synced 2026-08-13 05:31:37 +08:00
Added un-subscribe event and covered the Events-module
This commit is contained in:
@@ -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();
|
||||
}
|
||||
}
|
||||
};
|
||||
}();
|
||||
|
||||
Reference in New Issue
Block a user