Skip to content

Commit

Permalink
added Marionette.extend as alias to Backbone's extend method
Browse files Browse the repository at this point in the history
  • Loading branch information
Derick Bailey committed Oct 7, 2012
1 parent a759a35 commit 3316ac0
Show file tree
Hide file tree
Showing 11 changed files with 60 additions and 23 deletions.
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
* Added `Marionette.addEventBinder` method to add all of the Backbone.Wreqr.EventBinder methods to a specified target object

* Misc
* Added `Marionette.extend` as alias to Backbone's `extend` method for more consistent use
* jQuery ($) support now works from global `$` or `window.jQuery`
* Updated to Underscore.js v1.4.1
* Updated to jQuery v1.8.2
Expand Down
27 changes: 27 additions & 0 deletions docs/marionette.functions.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,30 @@ of it being attached to the view. For example, the internal structure
used to store the events can change without worry about it interfering
with Marionette's views.

## Marionette.extend

Backbone's `extend` function is a useful utility to have, and is used in
various places in Marionette. To make the use of this method more consistent,
Backbone's `extend` has been aliased to `Marionette.extend`. This allows
you to get the extend functionality for your object without having to
decide if you want to use Backbone.View or Backbone.Model or another
Backbone object to grab the method from.

```js
var Foo = function(){};

// use Marionette.extend to make Foo extendable, just like other
// Backbone and Marionette objects
Foo.extend = Marionette.extend;

// Now Foo can be extended to create a new type, with methods
var Bar = Foo.extend({

someMethod: function(){ ... }

// ...
});

// Create an instance of Bar
var b = new Bar();
```
4 changes: 2 additions & 2 deletions grunt.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ module.exports = function(grunt) {
'public/javascripts/backbone.wreqr.js',
'src/marionette.js',
'spec/javascripts/support/marionette.support.js',
'src/marionette.helpers.js',
'src/marionette.triggermethod.js',
'src/marionette.eventbinder.js',
'src/marionette.view.js',
Expand All @@ -64,8 +65,7 @@ module.exports = function(grunt) {
'src/marionette.templatecache.js',
'src/marionette.renderer.js',
'src/marionette.callbacks.js',
'src/marionette.eventaggregator.js',
'src/marionette.helpers.js'
'src/marionette.eventaggregator.js'
],
helpers : 'spec/javascripts/helpers/*.js',
specs : 'spec/javascripts/**/*.spec.js'
Expand Down
19 changes: 11 additions & 8 deletions lib/amd/backbone.marionette.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,15 @@
Backbone.Marionette = Marionette = (function(Backbone, _, $){
var Marionette = {};

// Helpers
// -------

// For slicing `arguments` in functions
var slice = Array.prototype.slice;

// Borrow the Backbone `extend` method so we can use it as needed
Marionette.extend = Backbone.Model.extend;

// Trigger an event and a corresponding method name. Examples:
//
// `this.triggerMethod("foo")` will trigger the "foo" event and
Expand Down Expand Up @@ -849,7 +858,7 @@
});

// Copy the `extend` function used by Backbone's classes
Marionette.Region.extend = Backbone.View.extend;
Marionette.Region.extend = Marionette.extend;

// Layout
// ------
Expand Down Expand Up @@ -1037,7 +1046,7 @@
});

// Copy the `extend` function used by Backbone's classes
Marionette.Application.extend = Backbone.View.extend;
Marionette.Application.extend = Marionette.extend;

// AppRouter
// ---------
Expand Down Expand Up @@ -1492,12 +1501,6 @@
// https://github.com/marionettejs/backbone.wreqr
Marionette.EventAggregator = Backbone.Wreqr.EventAggregator;

// Helpers
// -------

// For slicing `arguments` in functions
var slice = Array.prototype.slice;


return Marionette;
})(Backbone, _, $ || window.jQuery || window.Zepto || window.ender);
Expand Down
2 changes: 1 addition & 1 deletion lib/amd/backbone.marionette.min.js

Large diffs are not rendered by default.

19 changes: 11 additions & 8 deletions lib/backbone.marionette.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,15 @@
Backbone.Marionette = Marionette = (function(Backbone, _, $){
var Marionette = {};

// Helpers
// -------

// For slicing `arguments` in functions
var slice = Array.prototype.slice;

// Borrow the Backbone `extend` method so we can use it as needed
Marionette.extend = Backbone.Model.extend;

// Trigger an event and a corresponding method name. Examples:
//
// `this.triggerMethod("foo")` will trigger the "foo" event and
Expand Down Expand Up @@ -833,7 +842,7 @@ _.extend(Marionette.Region.prototype, Backbone.Events, {
});

// Copy the `extend` function used by Backbone's classes
Marionette.Region.extend = Backbone.View.extend;
Marionette.Region.extend = Marionette.extend;

// Layout
// ------
Expand Down Expand Up @@ -1021,7 +1030,7 @@ _.extend(Marionette.Application.prototype, Backbone.Events, {
});

// Copy the `extend` function used by Backbone's classes
Marionette.Application.extend = Backbone.View.extend;
Marionette.Application.extend = Marionette.extend;

// AppRouter
// ---------
Expand Down Expand Up @@ -1476,12 +1485,6 @@ _.extend(Marionette.Callbacks.prototype, {
// https://github.com/marionettejs/backbone.wreqr
Marionette.EventAggregator = Backbone.Wreqr.EventAggregator;

// Helpers
// -------

// For slicing `arguments` in functions
var slice = Array.prototype.slice;


return Marionette;
})(Backbone, _, $ || window.jQuery || window.Zepto || window.ender);
2 changes: 1 addition & 1 deletion lib/backbone.marionette.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/marionette.application.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,4 @@ _.extend(Marionette.Application.prototype, Backbone.Events, {
});

// Copy the `extend` function used by Backbone's classes
Marionette.Application.extend = Backbone.View.extend;
Marionette.Application.extend = Marionette.extend;
3 changes: 3 additions & 0 deletions src/marionette.helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,6 @@

// For slicing `arguments` in functions
var slice = Array.prototype.slice;

// Borrow the Backbone `extend` method so we can use it as needed
Marionette.extend = Backbone.Model.extend;
2 changes: 1 addition & 1 deletion src/marionette.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
Backbone.Marionette = Marionette = (function(Backbone, _, $){
var Marionette = {};

//= marionette.helpers.js
//= marionette.triggerMethod.js
//= marionette.eventbinder.js
//= marionette.view.js
Expand All @@ -16,7 +17,6 @@ Backbone.Marionette = Marionette = (function(Backbone, _, $){
//= marionette.renderer.js
//= marionette.callbacks.js
//= marionette.eventaggregator.js
//= marionette.helpers.js

return Marionette;
})(Backbone, _, $ || window.jQuery || window.Zepto || window.ender);
2 changes: 1 addition & 1 deletion src/marionette.region.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,4 +170,4 @@ _.extend(Marionette.Region.prototype, Backbone.Events, {
});

// Copy the `extend` function used by Backbone's classes
Marionette.Region.extend = Backbone.View.extend;
Marionette.Region.extend = Marionette.extend;

0 comments on commit 3316ac0

Please sign in to comment.