mirror of
https://github.com/logsol/chuck.js.git
synced 2026-05-11 18:47:35 +00:00
Merge branch 'restructuring' of github.com:logsol/chuck.js into restructuring
This commit is contained in:
commit
b8e6a967ee
2 changed files with 24 additions and 23 deletions
41
app/Game/Server/NotificationCenter.js
Normal file → Executable file
41
app/Game/Server/NotificationCenter.js
Normal file → Executable file
|
|
@ -1,32 +1,30 @@
|
||||||
define(function() {
|
define(
|
||||||
|
|
||||||
function NotificationCenter() {
|
var NotificationCenter = {
|
||||||
this.topics = {};
|
topics: {},
|
||||||
this.subUid = -1;
|
subUid: -1
|
||||||
}
|
};
|
||||||
|
|
||||||
NotificationCenter.prototype.trigger = function(topic, args) {
|
NotificationCenter.trigger = function(topic, args) {
|
||||||
if (!this.topics[topic]) {
|
if (!NotificationCenter.topics[topic]) {
|
||||||
throw "No such topic " + topic + ". Could not trigger.";
|
throw "No such topic " + topic + ". Could not trigger.";
|
||||||
}
|
}
|
||||||
|
|
||||||
var subscribers = this.topics[topic];
|
var subscribers = NotificationCenter.topics[topic];
|
||||||
var len = subscribers ? subscribers.length : 0;
|
var len = subscribers ? subscribers.length : 0;
|
||||||
|
|
||||||
while (len--) {
|
while (len--) {
|
||||||
subscribers[len].func(topic, args);
|
subscribers[len].func(topic, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
return this;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
NotificationCenter.prototype.on = function(topic, func) {
|
NotificationCenter.on = function(topic, func) {
|
||||||
if (!this.topics[topic]) {
|
if (!NotificationCenter.topics[topic]) {
|
||||||
this.topics[topic] = [];
|
NotificationCenter.topics[topic] = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
var token = ( ++this.subUid ).toString();
|
var token = ( ++NotificationCenter.subUid ).toString();
|
||||||
this.topics[topic].push({
|
NotificationCenter.topics[topic].push({
|
||||||
token: token,
|
token: token,
|
||||||
func: func
|
func: func
|
||||||
});
|
});
|
||||||
|
|
@ -34,19 +32,18 @@ define(function() {
|
||||||
return token;
|
return token;
|
||||||
}
|
}
|
||||||
|
|
||||||
NotificationCenter.prototype.off = function(token) {
|
NotificationCenter.off = function(token) {
|
||||||
|
|
||||||
for(var m in this.topics) {
|
for(var m in NotificationCenter.topics) {
|
||||||
if (this.topics[m]) {
|
if (NotificationCenter.topics[m]) {
|
||||||
for(var i = 0, j = this.topics[m].length; i < j; i++) {
|
for(var i = 0, j = NotificationCenter.topics[m].length; i < j; i++) {
|
||||||
if (this.topics[m][i].token === token) {
|
if (NotificationCenter.topics[m][i].token === token) {
|
||||||
this.topics[m].splice(i, 1);
|
NotificationCenter.topics[m].splice(i, 1);
|
||||||
return token;
|
return token;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return this;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return NotificationCenter;
|
return NotificationCenter;
|
||||||
|
|
|
||||||
6
app/Lib/Utilities/RequestAnimFrame.js
Normal file → Executable file
6
app/Lib/Utilities/RequestAnimFrame.js
Normal file → Executable file
|
|
@ -1,4 +1,8 @@
|
||||||
define(['Chuck/Settings'], function(Settings) {
|
define([
|
||||||
|
'Game/Config/Settings'
|
||||||
|
],
|
||||||
|
|
||||||
|
function(Settings) {
|
||||||
|
|
||||||
var requestAnimFrame = (function(){
|
var requestAnimFrame = (function(){
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue