Skip to content

Instantly share code, notes, and snippets.

@rhumlover
Created March 6, 2013 10:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rhumlover/5098284 to your computer and use it in GitHub Desktop.
Save rhumlover/5098284 to your computer and use it in GitHub Desktop.
(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