Skip to content

Instantly share code, notes, and snippets.

@futuraprime
Created December 15, 2011 14:42
Show Gist options
  • Save futuraprime/1481323 to your computer and use it in GitHub Desktop.
Save futuraprime/1481323 to your computer and use it in GitHub Desktop.
A potential rewrite of the toura.component function
toura.component = function(name, proto, opts) {
var ancestors = [toura._Component];
var namespace = opts.namespace || 'client.components';
if (opts.ancestors) {
// concat is a synonym for "push" when fed a non-array
ancestors = ancestors.concat(opts.ancestors);
}
var p = dojo.mixin(proto, {
templateString : proto.componentTemplate || '%div',
prepareData : function() {
this.inherited(arguments);
if (proto.prep) {
proto.prep.call(this);
}
},
postCreate : function() {
this.inherited(arguments);
if (window.jQuery) { this.$domNode = jQuery(this.domNode); }
},
startup : function() {
this.inherited(arguments);
if (proto.init) {
proto.init.call(this);
}
}
});
dojo.declare(namespace + '.' + name, ancestors, p);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment