marionettejs/backbone.marionette — pull request #963 by zourtney (2014-02-28 15:47:24+00:00)
Title: Trigger 'onClose' with arguments supplied to 'close'

I have edited *marionette.view* and *marionette.controller* to trigger `onClose` with any arguments supplied to `close`. Only one line changed (in each file):

this.triggerMethod("close");

Became:

this.triggerMethod.apply(this, ["close"].concat(slice(arguments)));

----

**Why:** There are times when `onClose` may need to behave differently, depending on how it's invoked. This added flexibility allows for "smarter" cleanup, especially of child views. In the system I'm working on, we often pass a boolean stating whether or not child views' `$el` should be removed from the DOM.

Contrived example:

var view = new (Marionette.View.extend({
onClose: function(destroyChildren) {
if (destroyChildren) {
// do it
}
}
}));

view.close(true);

**How:** This issue is easily solved by appending `arguments` to the existing `triggerMethod("close")` calls.

close: function(){
...
this.triggerMethod.apply(this, ["close"].concat(slice(arguments)));
...
}

Since other code (*marionette.itemview*, etc) takes care apply arguments when calling `close`, only *marionette.view* needs to change.

I applied this same change to *marionette.controller*.

-----

**Additional info:** The pull request is split into 3 commits Chronologically, they are:

1. Change to *marionette.view* and updated test
2. Change to *marionette.controller* and updated test
3. Files generated from running `grunt [default]` (updated lib, code coverage, etc). I'm not sure if these are generally committed with pull requests -- this is my first! The diff shows a bunch of `listenTo` syntax changes in the distribution files that are not related to my change. If it'd be better to submit the pull request without this commit, let me know.