mirror of
https://github.com/logsol/chuck.js.git
synced 2026-05-11 10:37:34 +00:00
moved Protocol and NotificationCenter to Lib/Utilities
This commit is contained in:
parent
93e8133c89
commit
3aa89fc8d6
24 changed files with 30 additions and 30 deletions
40
app/Lib/Utilities/Protocol/Helper.js
Executable file
40
app/Lib/Utilities/Protocol/Helper.js
Executable file
|
|
@ -0,0 +1,40 @@
|
|||
define([
|
||||
"Lib/Utilities/Protocol/Parser",
|
||||
"Lib/Utilities/Exception"
|
||||
],
|
||||
|
||||
function (Parser, Exception) {
|
||||
|
||||
var Helper = {}
|
||||
|
||||
Helper.encodeCommand = function (command, options) {
|
||||
var message = {};
|
||||
message[command] = options || null;
|
||||
return Parser.encode(message);
|
||||
}
|
||||
|
||||
Helper.applyCommand = function(options, target) {
|
||||
|
||||
var message;
|
||||
if (typeof options == "string") {
|
||||
message = Parser.decode(options);
|
||||
} else {
|
||||
message = options;
|
||||
}
|
||||
|
||||
// The for loop is only here to get the key, it is not designed to get multiple commands
|
||||
for(var command in message) {
|
||||
var methodName = "on" + command.toUpperCaseFirstChar();
|
||||
var options = message[command];
|
||||
|
||||
if (!target[methodName]) {
|
||||
throw new Exception("Helper.applyCommand:", target, "has no method", methodName);
|
||||
}
|
||||
|
||||
target[methodName].call(target, options);
|
||||
}
|
||||
};
|
||||
|
||||
return Helper;
|
||||
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue