},
constructor: function(behaviorAttributes, behaviorOptions, viewOptions) {
behaviorOptions = behaviorOptions || {};
if (!behaviorOptions.view) {
throw new Error('Torso Behavior constructed without behaviorOptions.view');
}
this.view = behaviorOptions.view;
if (!behaviorOptions.alias) {
throw new Error('Torso Behavior constructed without behaviorOptions.alias');
}
this.alias = behaviorOptions.alias;
this.cid = this.cid || _.uniqueId(this.cidPrefix);
this.__bindLifecycleMethods();
NestedCell.apply(this, arguments);
this.__bindEventCallbacks();
},
__augmentViewPrepare: function() {
var originalViewPrepareFn = _.bind(this.view.prepare, this.view);
var wrappedPrepareFn = _.wrap(originalViewPrepareFn, this.__viewPrepareWrapper);
this.view.prepare = _.bind(wrappedPrepareFn, this);
},
__viewPrepareWrapper: function(viewPrepare) {
var viewContext = viewPrepare() || {};
var behaviorContext = _.omit(this.toJSON(), 'view');
_.extend(behaviorContext, this.prepare());
viewContext[this.alias] = behaviorContext;
return viewContext;
},
__bindLifecycleMethods: function() {
this.listenTo(this.view, 'initialize:complete', this.__augmentViewPrepare);
this.listenTo(this.view, 'before-dispose-callback', this.__dispose);
_.each(eventMap, function(callback, event) {
this.listenTo(this.view, event, this[callback]);
}, this);
},
__bindEventCallbacks: function() {
var behaviorEvents = _.result(this, 'events');
var viewEvents = this.view.events;
if (!viewEvents) {
if (!behaviorEvents) {
return;
} else {
viewEvents = {};
}
}
var namespacedEvents = this.__namespaceEvents(behaviorEvents);
var boundBehaviorEvents = this.__bindEventCallbacksToBehavior(namespacedEvents);
if (_.isFunction(viewEvents)) {
this.view.events = _.wrap(_.bind(viewEvents, this.view), function(viewEventFunction) {
return _.extend(boundBehaviorEvents, viewEventFunction());
});
} else if (_.isObject(viewEvents)) {
this.view.events = _.extend(boundBehaviorEvents, viewEvents);
}
},
__namespaceEvents: function(eventHash) {