vendor/assets/javascripts/emerson/view.js in emerson-0.0.7 vs vendor/assets/javascripts/emerson/view.js in emerson-0.0.8
- old
+ new
@@ -211,19 +211,42 @@
//
// 1. The provided setup block.
// 2. A "subclass", extended with the View prototype.
function construct(name, setup) {
var sub = _.extend($sub(), {
- constructor : View,
- setup : _.extend({}, View.setup, setup)
+ constructor : View,
+ setup : _.extend({
+ initialize : function() {},
+ connected : false,
+ subscribe : {},
+ }, setup),
+ // experimental... allows for easier spec'ing of a view/trait
+ build : function build(element, mode) {
+ return instance(this, element, mode);
+ }
});
_.extend(sub.fn, View.prototype);
return sub;
}
+ // ### instance
+ // experimental (see `build` definition in `construct`).
+ function instance(def, element, mode) {
+ var setup = def.setup;
+ var built = def(element, element.context);
+ built.connect(setup.connected);
+
+ _.each(setup.subscribe, function(handler, key) {
+ bind(built, key, handler);
+ });
+
+ setup.initialize.call(built, mode);
+ return built;
+ }
+
// ### attach
// Given a (complex) list of keys, search the libraries for applicable View
// and Trait definitions to apply to the object.
//
// Keeps track of which definitions have been applied, and does not re-apply.
@@ -255,18 +278,20 @@
return; // do not re-apply.
}
// Build an instance, connect outlets, bind events, init and record.
if(def = library[key]) {
- setup = def.setup;
- built = def(self, self.context);
- built.connect(setup.connected);
-
- _.each(setup.subscribe, function(handler, key) {
- bind(built, key, handler);
- });
-
- setup.initialize.call(built, mode);
+ // experimental...
+ instance(def, self, mode);
+ // setup = def.setup;
+ // built = def(self, self.context);
+ // built.connect(setup.connected);
+ //
+ // _.each(setup.subscribe, function(handler, key) {
+ // bind(built, key, handler);
+ // });
+ //
+ // setup.initialize.call(built, mode);
set.push(id);
}
});
return this;