mirror of
https://github.com/logsol/chuck.js.git
synced 2026-05-11 10:37:34 +00:00
singleton NotificationCenter
This commit is contained in:
parent
55505106e4
commit
60462f48bf
2 changed files with 9 additions and 11 deletions
|
|
@ -38,10 +38,6 @@ function(Parent, PhysicsEngine, ViewController, KeyboardController, requestAnimF
|
|||
}
|
||||
}
|
||||
|
||||
GameController.prototype.destroy = function() {
|
||||
Parent.prototype.destroy.call(this);
|
||||
}
|
||||
|
||||
GameController.prototype.meJoined = function(user) {
|
||||
this.me = this.userJoined(user);
|
||||
this.keyboardController = new KeyboardController(this.me, this);
|
||||
|
|
|
|||
12
app/Game/Server/NotificationCenter.js
Normal file → Executable file
12
app/Game/Server/NotificationCenter.js
Normal file → Executable file
|
|
@ -1,4 +1,7 @@
|
|||
define(function() {
|
||||
define([
|
||||
],
|
||||
|
||||
function() {
|
||||
|
||||
function NotificationCenter() {
|
||||
this.topics = {};
|
||||
|
|
@ -6,6 +9,7 @@ define(function() {
|
|||
}
|
||||
|
||||
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