Skip to content

Commit

Permalink
bump and build v1.3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
samccone committed Nov 25, 2013
1 parent 3116913 commit 66268eb
Show file tree
Hide file tree
Showing 37 changed files with 686 additions and 361 deletions.
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"description" : "Make your Backbone.js apps dance with a composite application architecture!",
"url" : "http://marionettejs.org",
"main" : "./lib/backbone.marionette.js",
"version" : "1.2.3",
"version" : "1.3.0",

"keywords" : [
"backbone",
Expand Down
4 changes: 4 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
### v1.3.0 [view commit logs](https://github.com/marionettejs/backbone.marionette/compare/v1.2.3...v1.3.0)
* CompositeView / CollectionView
* Massive perf boost in rendering collection and composite views by using document fragments [jsPerf](http://jsperf.com/marionette-documentfragment-collectionview/5)

### v1.2.3 [view commit logs](https://github.com/marionettejs/backbone.marionette/compare/v1.2.2...v1.2.3)
* CompositeView
* Fixed bug where ```child views``` were being added before the initial render, thus raising errors.
Expand Down
127 changes: 90 additions & 37 deletions lib/backbone.marionette.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// MarionetteJS (Backbone.Marionette)
// ----------------------------------
// v1.2.3
// v1.3.0
//
// Copyright (c)2013 Derick Bailey, Muted Solutions, LLC.
// Distributed under MIT license
Expand Down Expand Up @@ -576,8 +576,8 @@ Marionette.MonitorDOMRefresh = (function(){
// Marionette.bindEntityEvents & unbindEntityEvents
// ---------------------------
//
// These methods are used to bind/unbind a backbone "entity" (collection/model)
// to methods on a target object.
// These methods are used to bind/unbind a backbone "entity" (collection/model)
// to methods on a target object.
//
// The first parameter, `target`, must have a `listenTo` method from the
// EventBinder object.
Expand All @@ -587,7 +587,7 @@ Marionette.MonitorDOMRefresh = (function(){
//
// The third parameter is a hash of { "event:name": "eventHandler" }
// configuration. Multiple handlers can be separated by a space. A
// function can be supplied instead of a string handler name.
// function can be supplied instead of a string handler name.

(function(Marionette){
"use strict";
Expand Down Expand Up @@ -629,7 +629,7 @@ Marionette.MonitorDOMRefresh = (function(){
target.stopListening(entity, evt, method, target);
}


// generic looping function
function iterateEvents(target, entity, bindings, functionCallback, stringCallback){
if (!entity || !bindings) { return; }
Expand All @@ -642,7 +642,7 @@ Marionette.MonitorDOMRefresh = (function(){
// iterate the bindings and bind them
_.each(bindings, function(methods, evt){

// allow for a function as the handler,
// allow for a function as the handler,
// or a list of event names as a string
if (_.isFunction(methods)){
functionCallback(target, entity, evt, methods);
Expand All @@ -652,7 +652,7 @@ Marionette.MonitorDOMRefresh = (function(){

});
}

// Export Public API
Marionette.bindEntityEvents = function(target, entity, bindings){
iterateEvents(target, entity, bindings, bindToFunction, bindFromStrings);
Expand All @@ -679,7 +679,7 @@ Marionette.Callbacks = function(){
_.extend(Marionette.Callbacks.prototype, {

// Add a callback to be executed. Callbacks added here are
// guaranteed to execute, even if they are added after the
// guaranteed to execute, even if they are added after the
// `run` method is called.
add: function(callback, contextOverride){
this._callbacks.push({cb: callback, ctx: contextOverride});
Expand All @@ -690,8 +690,8 @@ _.extend(Marionette.Callbacks.prototype, {
});
},

// Run all registered callbacks with the context specified.
// Additional callbacks can be added after this has been run
// Run all registered callbacks with the context specified.
// Additional callbacks can be added after this has been run
// and they will still be executed.
run: function(options, context){
this._deferred.resolve(context, options);
Expand All @@ -703,7 +703,7 @@ _.extend(Marionette.Callbacks.prototype, {
var callbacks = this._callbacks;
this._deferred = Marionette.$.Deferred();
this._callbacks = [];

_.each(callbacks, function(cb){
this.add(cb.cb, cb.ctx);
}, this);
Expand Down Expand Up @@ -740,7 +740,7 @@ _.extend(Marionette.Controller.prototype, Backbone.Events, {
}
});

// Region
// Region
// ------
//
// Manage the visual regions of your composite application. See
Expand Down Expand Up @@ -795,19 +795,19 @@ _.extend(Marionette.Region, {
}

var selector, RegionType;

// get the selector for the region

if (regionIsString) {
selector = regionConfig;
}
}

if (regionConfig.selector) {
selector = regionConfig.selector;
}

// get the type for the region

if (regionIsType){
RegionType = regionConfig;
}
Expand All @@ -819,7 +819,7 @@ _.extend(Marionette.Region, {
if (regionConfig.regionType) {
RegionType = regionConfig.regionType;
}

// build the region instance
var region = new RegionType({
el: selector
Expand Down Expand Up @@ -874,7 +874,7 @@ _.extend(Marionette.Region.prototype, Backbone.Events, {
if (isDifferentView || isViewClosed) {
this.open(view);
}

this.currentView = view;

Marionette.triggerMethod.call(this, "show", view);
Expand Down Expand Up @@ -914,8 +914,8 @@ _.extend(Marionette.Region.prototype, Backbone.Events, {
delete this.currentView;
},

// Attach an existing view to the region. This
// will not call `render` or `onShow` for the new view,
// Attach an existing view to the region. This
// will not call `render` or `onShow` for the new view,
// and will not replace the current HTML for the `el`
// of the region.
attachView: function(view){
Expand Down Expand Up @@ -1398,8 +1398,8 @@ Marionette.View = Backbone.View.extend({
// with underscore.js templates, serializing the view's model or collection,
// and calling several methods on extended views, such as `onRender`.
Marionette.ItemView = Marionette.View.extend({
// Setting up the inheritance chain which allows changes to

// Setting up the inheritance chain which allows changes to
// Marionette.View.prototype.constructor which allows overriding
constructor: function(){
Marionette.View.prototype.constructor.apply(this, slice(arguments));
Expand Down Expand Up @@ -1480,6 +1480,25 @@ Marionette.CollectionView = Marionette.View.extend({
Marionette.View.prototype.constructor.apply(this, slice(arguments));

this._initialEvents();
this.initRenderBuffer();
},

// Instead of inserting elements one by one into the page,
// it's much more performant to insert elements into a document
// fragment and then insert that document fragment into the page
initRenderBuffer: function() {
this.elBuffer = document.createDocumentFragment();
},

startBuffering: function() {
this.initRenderBuffer();
this.isBuffering = true;
},

endBuffering: function() {
this.appendBuffer(this, this.elBuffer);
this.initRenderBuffer();
this.isBuffering = false;
},

// Configured the initial events that the collection view
Expand Down Expand Up @@ -1538,6 +1557,8 @@ Marionette.CollectionView = Marionette.View.extend({
// more control over events being triggered, around the rendering
// process
_renderChildren: function(){
this.startBuffering();

this.closeEmptyView();
this.closeChildren();

Expand All @@ -1546,6 +1567,8 @@ Marionette.CollectionView = Marionette.View.extend({
} else {
this.showEmptyView();
}

this.endBuffering();
},

// Internal method to loop through each item in the
Expand Down Expand Up @@ -1608,9 +1631,9 @@ Marionette.CollectionView = Marionette.View.extend({
itemViewOptions = itemViewOptions.call(this, item, index);
}

// build the view
// build the view
var view = this.buildItemView(item, ItemView, itemViewOptions);

// set up the child view event forwarding
this.addChildViewEventForwarding(view);

Expand Down Expand Up @@ -1696,11 +1719,26 @@ Marionette.CollectionView = Marionette.View.extend({
}
},

// You might need to override this if you've overridden appendHtml
appendBuffer: function(collectionView, buffer) {
collectionView.$el.append(buffer);
},

// Append the HTML to the collection's `el`.
// Override this method to do something other
// then `.append`.
appendHtml: function(collectionView, itemView, index){
collectionView.$el.append(itemView.el);
if (collectionView.isBuffering) {
// buffering happens on reset events and initial renders
// in order to reduce the number of inserts into the
// document, which are expensive.
collectionView.elBuffer.appendChild(itemView.el);
}
else {
// If we've already rendered the main collection, just
// append the new items directly into the element.
collectionView.$el.append(itemView.el);
}
},

// Internal method to set up the `children` object for
Expand Down Expand Up @@ -1833,15 +1871,30 @@ Marionette.CompositeView = Marionette.CollectionView.extend({
return Marionette.Renderer.render(template, data);
},


// You might need to override this if you've overridden appendHtml
appendBuffer: function(compositeView, buffer) {
var $container = this.getItemViewContainer(compositeView);
$container.append(buffer);
},

// Appends the `el` of itemView instances to the specified
// `itemViewContainer` (a jQuery selector). Override this method to
// provide custom logic of how the child item view instances have their
// HTML appended to the composite view instance.
appendHtml: function(cv, iv, index){
var $container = this.getItemViewContainer(cv);
$container.append(iv.el);
appendHtml: function(compositeView, itemView, index){
if (compositeView.isBuffering) {
compositeView.elBuffer.appendChild(itemView.el);
}
else {
// If we've already rendered the main collection, just
// append the new items directly into the element.
var $container = this.getItemViewContainer(compositeView);
$container.append(itemView.el);
}
},


// Internal method to ensure an `$itemViewContainer` exists, for the
// `appendHtml` method to use.
getItemViewContainer: function(containerView){
Expand Down Expand Up @@ -1887,15 +1940,15 @@ Marionette.CompositeView = Marionette.CollectionView.extend({
// Used for composite view management and sub-application areas.
Marionette.Layout = Marionette.ItemView.extend({
regionType: Marionette.Region,

// Ensure the regions are available when the `initialize` method
// is called.
constructor: function (options) {
options = options || {};

this._firstRender = true;
this._initializeRegions(options);

Marionette.ItemView.prototype.constructor.call(this, options);
},

Expand All @@ -1906,7 +1959,7 @@ Marionette.Layout = Marionette.ItemView.extend({
render: function(){

if (this.isClosed){
// a previously closed layout means we need to
// a previously closed layout means we need to
// completely re-initialize the regions
this._initializeRegions();
}
Expand All @@ -1915,7 +1968,7 @@ Marionette.Layout = Marionette.ItemView.extend({
// reset the regions
this._firstRender = false;
} else if (!this.isClosed){
// If this is not the first render call, then we need to
// If this is not the first render call, then we need to
// re-initializing the `el` for each region
this._reInitializeRegions();
}
Expand Down Expand Up @@ -1966,7 +2019,7 @@ Marionette.Layout = Marionette.ItemView.extend({
},

// Internal method to initialize the regions that have been defined in a
// `regions` attribute on this layout.
// `regions` attribute on this layout.
_initializeRegions: function (options) {
var regions;
this._initRegionManager();
Expand Down Expand Up @@ -2123,7 +2176,7 @@ _.extend(Marionette.Application.prototype, Backbone.Events, {
this.triggerMethod("start", options);
},

// Add regions to your app.
// Add regions to your app.
// Accepts a hash of named strings or Region objects
// addRegions({something: "#someRegion"})
// addRegions({something: Region.extend({el: "#someRegion"}) });
Expand All @@ -2142,7 +2195,7 @@ _.extend(Marionette.Application.prototype, Backbone.Events, {
removeRegion: function(region) {
this._regionManager.removeRegion(region);
},

// Provides alternative access to regions
// Accepts the region name
// getRegion('main')
Expand Down Expand Up @@ -2340,7 +2393,7 @@ _.extend(Marionette.Module, {
},

_addModuleDefinition: function(parentModule, module, def, args){
var fn;
var fn;
var startWithParent;

if (_.isFunction(def)){
Expand All @@ -2352,7 +2405,7 @@ _.extend(Marionette.Module, {
// if an object is supplied
fn = def.define;
startWithParent = def.startWithParent;

} else {
// if nothing is supplied
startWithParent = true;
Expand Down
2 changes: 1 addition & 1 deletion lib/backbone.marionette.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions lib/backbone.marionette.min.js

Large diffs are not rendered by default.

Loading

0 comments on commit 66268eb

Please sign in to comment.