mirror of
https://github.com/BorysLevytskyi/BitwiseCmd.git
synced 2025-12-11 15:32:09 +01:00
31 lines
689 B
JavaScript
31 lines
689 B
JavaScript
(function(){
|
|
var commandr = {
|
|
|
|
};
|
|
|
|
function Command(name) {
|
|
this.name = name;
|
|
this.executionHandlers = [];
|
|
}
|
|
|
|
Command.prototype.execute = function (cmdArgs) {
|
|
cmdArgs = cmdArgs || {};
|
|
cmdArgs.commandHandled = false;
|
|
|
|
for(var i=0; i<this.executionHandlers.length; i++) {
|
|
this.executionHandlers[i](cmdArgs);
|
|
if(cmdArgs.commandHandled === true) {
|
|
return;
|
|
}
|
|
}
|
|
};
|
|
|
|
Command.prototype.subscribe = function (handler) {
|
|
this.executionHandlers.push(handler);
|
|
// TODO: unsubcribe
|
|
};
|
|
|
|
commandr.Command = Command;
|
|
|
|
window.commandr = commandr;
|
|
})(); |