Skip to content

Commit

Permalink
Merge pull request #1669 from agrberg/ar/fix_before_show_for_behaviors
Browse files Browse the repository at this point in the history
[fix] `before:show` trigger from region
  • Loading branch information
samccone committed Jul 18, 2014
2 parents f3e6990 + a60e0c8 commit be4cd62
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 12 deletions.
26 changes: 16 additions & 10 deletions spec/javascripts/behaviors.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -196,11 +196,12 @@ describe('Behaviors', function() {
describe('behavior UI', function() {
beforeEach(function() {
var suite = this;
this.onRenderStub = this.sinon.stub();
this.onShowStub = this.sinon.stub();
this.onDestroyStub = this.sinon.stub();
this.onFooClickStub = this.sinon.stub();
this.onBarClickStub = this.sinon.stub();
this.onRenderStub = this.sinon.stub();
this.onBeforeShowStub = this.sinon.stub();
this.onShowStub = this.sinon.stub();
this.onDestroyStub = this.sinon.stub();
this.onFooClickStub = this.sinon.stub();
this.onBarClickStub = this.sinon.stub();

this.behaviors = {
foo: Marionette.Behavior.extend({
Expand All @@ -210,11 +211,12 @@ describe('Behaviors', function() {
'click @ui.foo': 'onFooClick',
'click @ui.bar': 'onBarClick'
},
onRender : this.onRenderStub,
onShow : this.onShowStub,
onDestroy : this.onDestroyStub,
onFooClick : this.onFooClickStub,
onBarClick : this.onBarClickStub
onRender : this.onRenderStub,
onBeforeShow : this.onBeforeShowStub,
onShow : this.onShowStub,
onDestroy : this.onDestroyStub,
onFooClick : this.onFooClickStub,
onBarClick : this.onBarClickStub
})
};
Marionette.Behaviors.behaviorsLookup = this.behaviors;
Expand Down Expand Up @@ -295,6 +297,10 @@ describe('Behaviors', function() {
this.layoutView.destroy();
});

it('should call onBeforeShow', function() {
expect(this.onBeforeShowStub).to.have.been.calledOnce;
});

it('should call onShow', function() {
expect(this.onShowStub).to.have.been.calledOnce;
});
Expand Down
9 changes: 7 additions & 2 deletions src/marionette.region.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* jshint maxcomplexity: 10, maxstatements: 27 */
/* jshint maxcomplexity: 10, maxstatements: 28 */

// Region
// ------
Expand Down Expand Up @@ -161,7 +161,12 @@ _.extend(Marionette.Region.prototype, Backbone.Events, {
}

this.triggerMethod('before:show', view);
this.triggerMethod.call(view, 'before:show');

if (_.isFunction(view.triggerMethod)) {
view.triggerMethod('before:show');
} else {
this.triggerMethod.call(view, 'before:show');
}

this.attachHtml(view);
this.currentView = view;
Expand Down

0 comments on commit be4cd62

Please sign in to comment.