Skip to content

Instantly share code, notes, and snippets.

@spolu
Created November 26, 2012 07:13
Show Gist options
  • Save spolu/4146982 to your computer and use it in GitHub Desktop.
Save spolu/4146982 to your computer and use it in GitHub Desktop.
Sweet Factory and GrandCentral
var factory = function(spec, my) {
[...]
my.grandcentral = new EventEmitter();
// public
var user; /* user(spec, my); */
// private
var forward; /* forward(obj, type, evt); */
var that = {};
forward = function(obj, type, evt) {
obj.on(evt, function() {
my.grandcentral.emit(type + ':' + evt, arguments);
});
};
user = function(spec) {
var usr = user(spec);
forward(usr, 'user', 'create');
forward(usr, 'user', 'calendar');
forward(usr, 'user', 'delete');
return usr;
};
fwk.getter(that, 'grandcentral', my, 'grandcentral');
fwk.method(that, 'user', user, _super);
return that;
}
exports.get = function() {
if(!_factory)
_factory = factory({});
return _factory;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment