mirror of
https://github.com/logsol/chuck.js.git
synced 2026-05-11 18:47:35 +00:00
singleton NotificationCenter
This commit is contained in:
parent
55505106e4
commit
60462f48bf
2 changed files with 9 additions and 11 deletions
16
app/Game/Server/NotificationCenter.js
Normal file → Executable file
16
app/Game/Server/NotificationCenter.js
Normal file → Executable file
|
|
@ -1,11 +1,15 @@
|
|||
define(function() {
|
||||
define([
|
||||
],
|
||||
|
||||
function NotificationCenter() {
|
||||
function() {
|
||||
|
||||
function NotificationCenter() {
|
||||
this.topics = {};
|
||||
this.subUid = -1;
|
||||
}
|
||||
}
|
||||
|
||||
NotificationCenter.prototype.trigger = function(topic, args) {
|
||||
|
||||
if (!this.topics[topic]) {
|
||||
throw "No such topic " + topic + ". Could not trigger.";
|
||||
}
|
||||
|
|
@ -16,11 +20,10 @@ define(function() {
|
|||
while (len--) {
|
||||
subscribers[len].func(topic, args);
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
NotificationCenter.prototype.on = function(topic, func) {
|
||||
|
||||
if (!this.topics[topic]) {
|
||||
this.topics[topic] = [];
|
||||
}
|
||||
|
|
@ -46,8 +49,7 @@ define(function() {
|
|||
}
|
||||
}
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
return NotificationCenter;
|
||||
return new NotificationCenter(); // making it singletone
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue