Created
March 6, 2013 10:09
-
-
Save rhumlover/5098284 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function() { | |
window.streamApp.service('Mediator', function($rootScope, Common, Events) { | |
var Mediator; | |
Mediator = (function() { | |
var dict; | |
dict = {}; | |
function Mediator() {} | |
Mediator.prototype.register = function(name, ob) { | |
dict[name] = ob; | |
}; | |
Mediator.prototype.get = function(name) { | |
if (~Object.keys(dict).indexOf(name)) { | |
return dict[name]; | |
} else { | |
console.warn('[Mediator] get(): Object referenced as "%s" doesn\'t exists', name); | |
} | |
return null; | |
}; | |
Mediator.prototype.callMethod = function(objectName, method) { | |
var ob; | |
ob = this.get(objectName); | |
if (!!ob && typeof ob[method] === 'function') { | |
ob[method].call(ob); | |
} | |
}; | |
Mediator.prototype.activate = function(name) { | |
this.callMethod(name, 'activate'); | |
}; | |
Mediator.prototype.deactivate = function(name) { | |
this.callMethod(name, 'deactivate'); | |
}; | |
return Mediator; | |
})(); | |
return new Mediator(); | |
}); | |
}).call(this); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment