marionette.toolkit.component
Advanced tools
Comparing version 0.4.0 to 0.4.1
/** | ||
* marionette.toolkit - A collection of opinionated Backbone.Marionette extensions for large scale application architecture. | ||
* @version v0.4.0 | ||
* @version v0.4.1 | ||
* @link https://github.com/RoundingWellOS/marionette.toolkit | ||
@@ -51,3 +51,3 @@ * @license MIT | ||
constructor: function constructor(stateAttrs, options) { | ||
options = options || {}; | ||
options = _.extend({}, options); | ||
@@ -157,3 +157,3 @@ // Make defaults available to this | ||
_getViewClass: function _getViewClass(options) { | ||
options = options || {}; | ||
options = _.extend({}, options); | ||
@@ -160,0 +160,0 @@ var ViewClass = this.getOption("ViewClass"); |
/** | ||
* marionette.toolkit - A collection of opinionated Backbone.Marionette extensions for large scale application architecture. | ||
* @version v0.4.0 | ||
* @version v0.4.1 | ||
* @link https://github.com/RoundingWellOS/marionette.toolkit | ||
* @license MIT | ||
*/ | ||
"use strict";var _=require("underscore"),Backbone=require("backbone"),Marionette=require("backbone.marionette"),StateClass=require("marionette.toolkit.state-class"),Component=StateClass.extend({ViewClass:Marionette.ItemView,viewEventPrefix:"view",viewOptions:{},constructor:function(e,t){t=t||{},_.extend(this,_.pick(t,["viewEventPrefix","ViewClass","viewOptions","region"])),StateClass.call(this,t),this._setStateDefaults(e)},_shouldDestroy:!0,_setStateDefaults:function(e){this.setState(e,{silent:!0})},showIn:function(e,t){return this.region=e,this.show(t),this},show:function(e){if(this._isShown)throw new Marionette.Error({name:"ComponentShowError",message:"Component has already been shown in a region."});if(!this.region)throw new Marionette.Error({name:"ComponentRegionError",message:"Component has no defined region."});return this.triggerMethod("before:show"),this.renderView(e),this._isShown=!0,this.triggerMethod("show"),this.listenTo(this.region,"empty",this._destroy),this},_getViewClass:function(e){e=e||{};var t=this.getOption("ViewClass");if(t.prototype instanceof Backbone.View||t===Backbone.View)return t;if(_.isFunction(t))return t.call(this,e);throw new Marionette.Error({name:"InvalidViewClassError",message:'"ViewClass" must be a view class or a function that returns a view class'})},renderView:function(e){var t=this._getViewClass(e),i=this.mixinOptions(e),s=this.buildView(t,i);return this.currentView=s,this._proxyViewEvents(s),this.triggerMethod("before:render:view",s),this._shouldDestroy=!1,this.region.show(s),this._shouldDestroy=!0,this.triggerMethod("render:view",s),this},_proxyViewEvents:function(e){var t=this.getOption("viewEventPrefix");e.on("all",function(){var i=_.toArray(arguments),s=i[0];i[0]=t+":"+s,i.splice(1,0,e),this.triggerMethod.apply(this,i)},this)},mixinOptions:function(e){var t=_.result(this,"viewOptions");return _.extend({stateModel:this.getState()},t,e)},buildView:function(e,t){return new e(t)},_destroy:function(){this._shouldDestroy&&StateClass.prototype.destroy.apply(this,arguments)},_emptyRegion:function(e){this.region&&(this.stopListening(this.region,"empty"),this.region.empty(e))},destroy:function(e){this._emptyRegion(e),this._shouldDestroy=!0,this._destroy(e)}}),component=Component;module.exports=component; | ||
"use strict";var _=require("underscore"),Backbone=require("backbone"),Marionette=require("backbone.marionette"),StateClass=require("marionette.toolkit.state-class"),Component=StateClass.extend({ViewClass:Marionette.ItemView,viewEventPrefix:"view",viewOptions:{},constructor:function(e,t){t=_.extend({},t),_.extend(this,_.pick(t,["viewEventPrefix","ViewClass","viewOptions","region"])),StateClass.call(this,t),this._setStateDefaults(e)},_shouldDestroy:!0,_setStateDefaults:function(e){this.setState(e,{silent:!0})},showIn:function(e,t){return this.region=e,this.show(t),this},show:function(e){if(this._isShown)throw new Marionette.Error({name:"ComponentShowError",message:"Component has already been shown in a region."});if(!this.region)throw new Marionette.Error({name:"ComponentRegionError",message:"Component has no defined region."});return this.triggerMethod("before:show"),this.renderView(e),this._isShown=!0,this.triggerMethod("show"),this.listenTo(this.region,"empty",this._destroy),this},_getViewClass:function(e){e=_.extend({},e);var t=this.getOption("ViewClass");if(t.prototype instanceof Backbone.View||t===Backbone.View)return t;if(_.isFunction(t))return t.call(this,e);throw new Marionette.Error({name:"InvalidViewClassError",message:'"ViewClass" must be a view class or a function that returns a view class'})},renderView:function(e){var t=this._getViewClass(e),i=this.mixinOptions(e),s=this.buildView(t,i);return this.currentView=s,this._proxyViewEvents(s),this.triggerMethod("before:render:view",s),this._shouldDestroy=!1,this.region.show(s),this._shouldDestroy=!0,this.triggerMethod("render:view",s),this},_proxyViewEvents:function(e){var t=this.getOption("viewEventPrefix");e.on("all",function(){var i=_.toArray(arguments),s=i[0];i[0]=t+":"+s,i.splice(1,0,e),this.triggerMethod.apply(this,i)},this)},mixinOptions:function(e){var t=_.result(this,"viewOptions");return _.extend({stateModel:this.getState()},t,e)},buildView:function(e,t){return new e(t)},_destroy:function(){this._shouldDestroy&&StateClass.prototype.destroy.apply(this,arguments)},_emptyRegion:function(e){this.region&&(this.stopListening(this.region,"empty"),this.region.empty(e))},destroy:function(e){this._emptyRegion(e),this._shouldDestroy=!0,this._destroy(e)}}),component=Component;module.exports=component; | ||
//# sourceMappingURL=Component.min.js.map |
{ | ||
"name": "marionette.toolkit.component", | ||
"version": "0.4.0", | ||
"version": "0.4.1", | ||
"description": "Marionette.Toolkit’s `Component` as a module.", | ||
@@ -20,5 +20,5 @@ "main": "./Component.js", | ||
"backbone.marionette": "^2.1.0", | ||
"backbone": "1.0.0 - 1.1.2", | ||
"underscore": "1.4.4 - 1.8.3" | ||
"backbone": "^1.0.0", | ||
"underscore": "^1.4.4" | ||
} | ||
} |
@@ -1,2 +0,2 @@ | ||
# Marionette.Toolkit.Component v0.4.0 | ||
# Marionette.Toolkit.Component v0.4.1 | ||
@@ -3,0 +3,0 @@ [Marionette.Toolkit](https://github.com/RoundingWellOS/marionette.toolkit)'s `Component` exported as a [Node.js](http://nodejs.org/)/[io.js](https://iojs.org/) module. |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
51513
+ Addedbackbone@1.3.31.6.0(transitive)
+ Addedunderscore@1.13.7(transitive)
- Removedbackbone@1.1.2(transitive)
Updatedbackbone@^1.0.0
Updatedunderscore@^1.4.4