backbone-subviews
Advanced tools
Comparing version 0.7.2 to 0.7.3
@@ -26,3 +26,2 @@ /* | ||
} | ||
}( this, function( _, Backbone, $ ) { | ||
@@ -70,2 +69,13 @@ var debugMode = true; | ||
// ****************** Additional private methods ****************** | ||
view._createSubview = function( subviewName, placeHolderDiv ) { | ||
// Return a new subview instance given a subview name and its placeHolderDiv. | ||
// Implemented as instance method so that this behavior may be customized / overridden. | ||
var subviewCreator = this.subviewCreators[ subviewName ]; | ||
if( _.isUndefined( subviewCreator ) ) throw new Error( "Can not find subview creator for subview named: " + subviewName ); | ||
return subviewCreator.apply( this ); | ||
}; | ||
// ****************** Private Utility Functions ****************** | ||
@@ -81,3 +91,3 @@ | ||
// detach each of our subviews that we have already created during previous | ||
// Detach each of our subviews that we have already created during previous | ||
// renders from the DOM, so that they do not loose their DOM events when | ||
@@ -100,17 +110,11 @@ // we re-render the contents of this view's DOM element. | ||
if( _.isUndefined( _this.subviews[ subviewName ] ) ) { | ||
// if the subview is not yet defined, then create it now using | ||
// the registered creator method in this.subviewCreators | ||
var subviewCreator = _this.subviewCreators[ subviewName ]; | ||
if( _.isUndefined( subviewCreator ) ) throw new Error( "Can not find subview creator for subview named: " + subviewName ); | ||
if( debugMode ) console.log( "Creating subview " + subviewName ); | ||
newSubview = subviewCreator.apply( _this ); | ||
newSubview = _this._createSubview( subviewName, thisPlaceHolderDiv ); | ||
if( newSubview === null ) return; // subview creators can return null to indicate that the subview should not be created | ||
_this.subviews[ subviewName ] = newSubview; | ||
} | ||
else { | ||
// if the subview is already defined, then use the existing subview instead | ||
// If the subview is already defined, then use the existing subview instead | ||
// of creating a new one. This allows us to re-render a parent view without | ||
// loosing any dynamic state data on the existing subview objects. | ||
// loosing any dynamic state data on the existing subview objects. To force | ||
// re-initialization of subviews, call view.removeSubviews before re-rendering. | ||
@@ -123,3 +127,3 @@ newSubview = _this.subviews[ subviewName ]; | ||
// now that all subviews have been created, render them one at a time, in the | ||
// Now that all subviews have been created, render them one at a time, in the | ||
// order they occur in the DOM. | ||
@@ -132,3 +136,3 @@ _.each( this.subviews, function( thisSubview, subviewName ) { | ||
// call this.onSubviewsRendered after everything is done (hook for application defined logic) | ||
// Call this.onSubviewsRendered after everything is done (hook for application defined logic) | ||
if( _.isFunction( this.onSubviewsRendered ) ) this.onSubviewsRendered.call( this ); | ||
@@ -135,0 +139,0 @@ if( _.isFunction( this._onSubviewsRendered ) ) this._onSubviewsRendered.call( this ); // depreciated. backwards compatibility for versions < 0.6. |
/* | ||
* Backbone.Subviews, v0.7 | ||
* Backbone.Subviews, v0.7.3 | ||
* Copyright (c)2013-2014 Rotunda Software, LLC. | ||
@@ -19,3 +19,2 @@ * Distributed under MIT license | ||
} | ||
}( this, function( _, Backbone, $ ) { | ||
@@ -60,2 +59,13 @@ Backbone.Subviews = {}; | ||
}; | ||
// ****************** Additional private methods ****************** | ||
view._createSubview = function( subviewName, placeHolderDiv ) { | ||
// Return a new subview instance given a subview name and its placeHolderDiv. | ||
// Implemented as instance method so that this behavior may be customized / overridden. | ||
var subviewCreator = this.subviewCreators[ subviewName ]; | ||
if( _.isUndefined( subviewCreator ) ) throw new Error( "Can not find subview creator for subview named: " + subviewName ); | ||
return subviewCreator.apply( this ); | ||
}; | ||
}; | ||
@@ -89,11 +99,4 @@ | ||
if( _.isUndefined( _this.subviews[ subviewName ] ) ) { | ||
// if the subview is not yet defined, then create it now using | ||
// the registered creator method in this.subviewCreators. | ||
var subviewCreator = _this.subviewCreators[ subviewName ]; | ||
if( _.isUndefined( subviewCreator ) ) throw new Error( "Can not find subview creator for subview named: " + subviewName ); | ||
newSubview = subviewCreator.apply( _this ); | ||
if( newSubview === null ) return; // subview creators can return null to indicate that the subview should not be created | ||
newSubview = _this._createSubview( subviewName, thisPlaceHolderDiv ); | ||
if( newSubview === null ) return; // subview creators can return null to indicate that the subview should not be created | ||
_this.subviews[ subviewName ] = newSubview; | ||
@@ -105,3 +108,3 @@ } | ||
// loosing any dynamic state data on the existing subview objects. To force | ||
// re-initialization of subviews, call view._removeSubviews before re-rendering. | ||
// re-initialization of subviews, call view.removeSubviews before re-rendering. | ||
@@ -108,0 +111,0 @@ newSubview = _this.subviews[ subviewName ]; |
{ | ||
"name": "backbone-subviews", | ||
"version": "0.7.2", | ||
"version": "0.7.3", | ||
"description": "A minimalist view mixin for creating and managing subviews in your Backbone.js applications.", | ||
@@ -5,0 +5,0 @@ "main": "backbone.subviews.js", |
@@ -13,3 +13,3 @@ # Backbone.Subviews | ||
* Automatically cleans up (i.e. removes) subviews when a parent view is removed. | ||
* Promotes small encapsulated ui components that can be reused with [parcelify](https://github.com/rotundasoftware/parcelify) or [cartero](https://github.com/rotundasoftware/cartero/). | ||
* Promotes small encapsulated ui components that can be reused (e.g. with [parcelify](https://github.com/rotundasoftware/parcelify) or [cartero](https://github.com/rotundasoftware/cartero/)). | ||
* Can be mixed into any view class. | ||
@@ -51,3 +51,3 @@ | ||
// after we are done rendering, our subviews will automatically be rendered in order | ||
// After we are done rendering, our subviews will automatically be rendered in order | ||
}, | ||
@@ -90,2 +90,9 @@ | ||
#### v0.7.3 (5/23/14) | ||
* Re-factored a bit so that the mechanism used to create subviews can be overriden if desired. | ||
* The placeHolderDiv is now be passed as the second argument to the functions in `subviewCreators` | ||
#### v0.7.2 (4/13/14) | ||
* Improved UMD wrapper to use DOM library already attached to jquery. | ||
#### v0.7.1 (4/6/14) | ||
@@ -92,0 +99,0 @@ * Relax `div` restriction on subview placeholder - placeholders can now be of any type of element. |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
453266
13027
105