singleton NotificationCenter

This commit is contained in:
Jeena Paradies 2012-07-22 02:21:34 +02:00
parent 55505106e4
commit 60462f48bf
2 changed files with 9 additions and 11 deletions

View file

@ -38,10 +38,6 @@ function(Parent, PhysicsEngine, ViewController, KeyboardController, requestAnimF
} }
} }
GameController.prototype.destroy = function() {
Parent.prototype.destroy.call(this);
}
GameController.prototype.meJoined = function(user) { GameController.prototype.meJoined = function(user) {
this.me = this.userJoined(user); this.me = this.userJoined(user);
this.keyboardController = new KeyboardController(this.me, this); this.keyboardController = new KeyboardController(this.me, this);

16
app/Game/Server/NotificationCenter.js Normal file → Executable file
View file

@ -1,11 +1,15 @@
define(function() { define([
],
function NotificationCenter() { function() {
function NotificationCenter() {
this.topics = {}; this.topics = {};
this.subUid = -1; this.subUid = -1;
} }
NotificationCenter.prototype.trigger = function(topic, args) { NotificationCenter.prototype.trigger = function(topic, args) {
if (!this.topics[topic]) { if (!this.topics[topic]) {
throw "No such topic " + topic + ". Could not trigger."; throw "No such topic " + topic + ". Could not trigger.";
} }
@ -16,11 +20,10 @@ define(function() {
while (len--) { while (len--) {
subscribers[len].func(topic, args); subscribers[len].func(topic, args);
} }
return this;
} }
NotificationCenter.prototype.on = function(topic, func) { NotificationCenter.prototype.on = function(topic, func) {
if (!this.topics[topic]) { if (!this.topics[topic]) {
this.topics[topic] = []; this.topics[topic] = [];
} }
@ -46,8 +49,7 @@ define(function() {
} }
} }
} }
return this;
} }
return NotificationCenter; return new NotificationCenter(); // making it singletone
}); });