mirror of
https://github.com/exane/not-gwent-online
synced 2024-11-23 19:36:53 +00:00
implement event system
This commit is contained in:
parent
db59735858
commit
14511b35fc
@ -36,6 +36,7 @@ var Battle = (function(){
|
||||
|
||||
r._id = null;
|
||||
|
||||
r.events = null;
|
||||
|
||||
r.init = function(){
|
||||
PubSub.subscribe("update", this.update.bind(this));
|
||||
@ -134,6 +135,27 @@ var Battle = (function(){
|
||||
});
|
||||
}
|
||||
|
||||
r.runEvent = function(eventid, target){
|
||||
target = target || this;
|
||||
this.events["on" + eventid].forEach(function(event) {
|
||||
event.call(target);
|
||||
});
|
||||
}
|
||||
|
||||
r.on = function(eventid, cb){
|
||||
if(!this.events["on" + eventid]) {
|
||||
this.events["on" + eventid] = [];
|
||||
}
|
||||
this.events["on" + eventid].push(cb);
|
||||
}
|
||||
|
||||
r.off = function(eventid) {
|
||||
this.events["on" + eventid].forEach(function(event) {
|
||||
event = null;
|
||||
});
|
||||
delete this.events["on" + eventid];
|
||||
}
|
||||
|
||||
/*r._setUpChannel = function() {
|
||||
var self = this;
|
||||
this._abilityChannel.watch(function(d) {
|
||||
|
Loading…
Reference in New Issue
Block a user