marionette.toolkit
Advanced tools
Comparing version 5.0.0-alpha.1 to 5.0.0-alpha.2
{ | ||
"name": "marionette.toolkit", | ||
"version": "4.0.0", | ||
"version": "5.0.0-alpha.2", | ||
"description": "A collection of opinionated Backbone.Marionette extensions for large scale application architecture.", | ||
@@ -37,5 +37,5 @@ "main": "./dist/marionette.toolkit.js", | ||
"backbone.marionette": "^3.0.0", | ||
"backbone": "^1.3.3", | ||
"underscore": "^1.8.3" | ||
"backbone": "~1.3.3", | ||
"underscore": "~1.8.3" | ||
} | ||
} |
/** | ||
* marionette.toolkit - A collection of opinionated Backbone.Marionette extensions for large scale application architecture. | ||
* @version v5.0.0-alpha.1 | ||
* @version v5.0.0-alpha.2 | ||
* @link https://github.com/RoundingWellOS/marionette.toolkit | ||
@@ -296,2 +296,13 @@ * @license MIT | ||
/** | ||
* Determines if `childApps` should restart | ||
* | ||
* @private | ||
* @method _shouldRestart | ||
*/ | ||
_shouldRestart: function _shouldRestart(childApp) { | ||
return this._isRestarting && _.result(childApp, 'restartWithParent'); | ||
}, | ||
/** | ||
* Starts `childApps` if allowed by child | ||
@@ -305,8 +316,11 @@ * | ||
var shouldStartOption = this._isRestarting ? 'restartWithParent' : 'startWithParent'; | ||
_.each(this._childApps, function (childApp) { | ||
if (!_.result(childApp, shouldStartOption)) return; | ||
if (_.result(childApp, 'startWithParent')) { | ||
childApp.start(); | ||
return; | ||
} | ||
var opts = _this2._getChildStartOpts(childApp); | ||
childApp.start(opts); | ||
if (_this2._shouldRestart(childApp)) { | ||
childApp.start(); | ||
} | ||
}); | ||
@@ -323,7 +337,13 @@ }, | ||
_stopChildApps: function _stopChildApps() { | ||
var shouldStopOption = this._isRestarting ? 'restartWithParent' : 'stopWithParent'; | ||
var _this3 = this; | ||
_.each(this._childApps, function (childApp) { | ||
if (_.result(childApp, shouldStopOption)) { | ||
if (_.result(childApp, 'stopWithParent')) { | ||
childApp.stop(); | ||
return; | ||
} | ||
if (_this3._shouldRestart(childApp)) { | ||
childApp.stop(); | ||
} | ||
}); | ||
@@ -1148,3 +1168,5 @@ }, | ||
*/ | ||
_onEmpty: function _onEmpty() { | ||
_onEmpty: function _onEmpty(region, view) { | ||
if (view !== this._view) return; | ||
this._removeView(); | ||
@@ -1600,3 +1622,3 @@ }, | ||
var VERSION = '5.0.0-alpha.1'; | ||
var VERSION = '5.0.0-alpha.2'; | ||
@@ -1603,0 +1625,0 @@ function MixinState(classDefinition) { |
/** | ||
* marionette.toolkit - A collection of opinionated Backbone.Marionette extensions for large scale application architecture. | ||
* @version v5.0.0-alpha.1 | ||
* @version v5.0.0-alpha.2 | ||
* @link https://github.com/RoundingWellOS/marionette.toolkit | ||
* @license MIT | ||
*/ | ||
!function(t,i){"object"==typeof exports&&"undefined"!=typeof module?i(exports,require("underscore"),require("backbone"),require("backbone.marionette")):"function"==typeof define&&define.amd?define(["exports","underscore","backbone","backbone.marionette"],i):i((t.Marionette=t.Marionette||{},t.Marionette.Toolkit=t.Marionette.Toolkit||{}),t._,t.Backbone,t.Marionette)}(this,function(t,i,e,n){"use strict";function s(t){var e=o;t.prototype.StateModel&&(e=i.omit(o,"StateModel")),i.extend(t.prototype,e)}i="default"in i?i.default:i,e="default"in e?e.default:e;var r=["StateModel","stateEvents"],o={StateModel:e.Model,initState:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return this._initState(t),this.delegateStateEvents(),this},_initState:function(t){this.mergeOptions(t,r),this._removeEventHandlers();var i=this._getStateModel(t);this._stateModel=new i(t.state),this._setEventHandlers()},delegateStateEvents:function(){return this.undelegateStateEvents(),this.bindEvents(this._stateModel,i.result(this,"stateEvents")),this},undelegateStateEvents:function(){return this.unbindEvents(this._stateModel),this},_setEventHandlers:function(){this.on("destroy",this._destroyState)},_removeEventHandlers:function(){this._stateModel&&(this.undelegateStateEvents(),this._stateModel.stopListening(),this.off("destroy",this._destroyState))},_getStateModel:function(t){if(this.StateModel.prototype instanceof e.Model||this.StateModel===e.Model)return this.StateModel;if(i.isFunction(this.StateModel))return this.StateModel.call(this,t);throw new Error('"StateModel" must be a model class or a function that returns a model class')},setState:function(){return this._stateModel.set.apply(this._stateModel,arguments)},resetStateDefaults:function(){var t=i.result(this._stateModel,"defaults");return this._stateModel.set(t)},getState:function(t){return t?this._stateModel.get.apply(this._stateModel,arguments):this._stateModel},toggleState:function(t,i){return arguments.length>1?this._stateModel.set(t,!!i):this._stateModel.set(t,!this._stateModel.get(t))},hasState:function(t){return this._stateModel.has(t)},_destroyState:function(){this._stateModel.stopListening()}},h=["childApps","childAppOptions"],a={_initChildApps:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};this._childApps={},this.mergeOptions(t,h);var e=this.childApps;e&&(i.isFunction(e)&&(e=e.call(this,t)),this.addChildApps(e))},_getChildStartOpts:function(t){var e=this,n=t._tkOpts||{},s={region:this.getRegion(n.regionName)};return i.each(n.getOptions,function(t){s[t]=e.getOption(t)}),s},_startChildApps:function(){var t=this,e=this._isRestarting?"restartWithParent":"startWithParent";i.each(this._childApps,function(n){if(i.result(n,e)){var s=t._getChildStartOpts(n);n.start(s)}})},_stopChildApps:function(){var t=this._isRestarting?"restartWithParent":"stopWithParent";i.each(this._childApps,function(e){i.result(e,t)&&e.stop()})},startChildApp:function(t,e){var n=this.getChildApp(t),s=this._getChildStartOpts(n);return n.start(i.extend(s,e))},stopChildApp:function(t,i){return this.getChildApp(t).stop(i)},_destroyChildApps:function(){i.each(this._childApps,function(t){i.result(t,"preventDestroy")||t.destroy()})},_buildAppFromObject:function(t){var e=t.AppClass,n=i.omit(t,"AppClass","regionName","getOptions"),s=this.buildApp(e,n);return s._tkOpts=i.pick(t,"regionName","getOptions"),s},_buildApp:function(t,e){return i.isFunction(t)?this.buildApp(t,e):i.isObject(t)?this._buildAppFromObject(t):void 0},buildApp:function(t,e){return e=i.extend({},this.childAppOptions,e),new t(e)},_ensureAppIsUnique:function(t){if(this._childApps[t])throw new Error('A child App with name "'+t+'" has already been added.')},addChildApps:function(t){i.each(t,i.bind(function(t,i){this.addChildApp(i,t)},this))},addChildApp:function(t,e,n){this._ensureAppIsUnique(t);var s=this._buildApp(e,n);if(!s)throw new Error("App build failed. Incorrect configuration.");return s._name=t,this._childApps[t]=s,s._on("destroy",i.partial(this._removeChildApp,t),this),this.isRunning()&&i.result(s,"startWithParent")&&s.start(),s},getName:function(){return this._name},getChildApps:function(){return i.clone(this._childApps)},getChildApp:function(t){return this._childApps[t]},_removeChildApp:function(t){delete this._childApps[t]._name,delete this._childApps[t]},removeChildApps:function(){var t=this.getChildApps();return i.each(this._childApps,i.bind(function(t,i){this.removeChildApp(i)},this)),t},removeChildApp:function(t,e){e=i.extend({},e);var n=this.getChildApp(t);if(n)return e.preventDestroy||i.result(n,"preventDestroy")?this._removeChildApp(t):n.destroy(),n}},p={_stopRunningEvents:function(){i.each(this._runningEvents,i.bind(function(t){this.off.apply(this,t)},this))},_stopRunningListeners:function(){i.each(this._runningListeningTo,i.bind(function(t){this.stopListening.apply(this,t)},this))},on:function(){return this._isRunning&&(this._runningEvents=this._runningEvents||[],this._runningEvents.push(arguments)),n.MnObject.prototype.on.apply(this,arguments)},_on:n.MnObject.prototype.on,listenTo:function(){return this._isRunning&&(this._runningListeningTo=this._runningListeningTo||[],this._runningListeningTo.push(arguments)),n.MnObject.prototype.listenTo.apply(this,arguments)},_listenTo:n.MnObject.prototype.listenTo,listenToOnce:function(){return this._isRunning&&(this._runningListeningTo=this._runningListeningTo||[],this._runningListeningTo.push(arguments)),n.MnObject.prototype.listenToOnce.apply(this,arguments)}},u={viewEventPrefix:!1,_buildEventProxies:function(){var t=i.result(this,"viewEvents")||{};this._viewEvents=this.normalizeMethods(t),this._viewTriggers=i.result(this,"viewTriggers")||{},this._viewEventPrefix=i.result(this,"viewEventPrefix")},_proxyViewEvents:function(t){this.listenTo(t,"all",this._childViewEventHandler)},_childViewEventHandler:function(t){for(var e=this._viewEvents,n=arguments.length,s=Array(n>1?n-1:0),r=1;r<n;r++)s[r-1]=arguments[r];i.isFunction(e[t])&&e[t].apply(this,s);var o=this._viewTriggers;i.isString(o[t])&&this.triggerMethod.apply(this,[o[t]].concat(s));var h=this._viewEventPrefix;if(h!==!1){var a=h+":"+t;this.triggerMethod.apply(this,[a].concat(s))}}},d=["startWithParent","restartWithParent","stopWithParent","startAfterInitialized","preventDestroy","StateModel","stateEvents","viewEventPrefix","viewEvents","viewTriggers"],l=n.Application.extend({_isRunning:!1,_isRestarting:!1,preventDestroy:!1,startAfterInitialized:!1,startWithParent:!1,stopWithParent:!0,restartWithParent:!1,constructor:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};this.mergeOptions(t,d),this.options=i.extend({},i.result(this,"options"),t),this._initChildApps(t),n.Application.call(this,t),i.result(this,"startAfterInitialized")&&this.start(t)},_ensureAppIsIntact:function(){if(this._isDestroyed)throw new Error("App has already been destroyed and cannot be used.")},isRunning:function(){return this._isRunning},isRestarting:function(){return this._isRestarting},start:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return this._ensureAppIsIntact(),this._isRunning?this:(t.region&&this.setRegion(t.region),t.view&&this.setView(t.view),this._initState(t),this._buildEventProxies(),this.triggerMethod("before:start",t),this._isRunning=!0,this._bindRunningEvents(),this._startChildApps(),this.triggerStart(t),this)},_bindRunningEvents:function(){this._region&&this._regionEventMonitor(),this._view&&this._proxyViewEvents(this._view),this.delegateStateEvents()},restart:function(){var t=this.getState().attributes;return this._isRestarting=!0,this.stop().start({state:t}),this._isRestarting=!1,this},triggerStart:function(t){this.triggerMethod("start",t)},stop:function(t){return this._isRunning?(this.triggerMethod("before:stop",t),this._stopChildApps(),this._isRunning=!1,this.triggerMethod("stop",t),this._stopRunningListeners(),this._stopRunningEvents(),this):this},destroy:function(){return this._isDestroyed?this:(this.stop(),this._removeView(),this._destroyChildApps(),n.Application.prototype.destroy.apply(this,arguments),this)},setRegion:function(t){return this._region&&this.stopListening(this._region),this._region=t,t.currentView&&this.setView(t.currentView),this._isRunning&&this._regionEventMonitor(),t},_regionEventMonitor:function(){this.listenTo(this._region,{"before:show":this._onBeforeShow,empty:this._onEmpty})},_onBeforeShow:function(t,i){this.setView(i)},_onEmpty:function(){this._removeView()},_removeView:function(){this._view&&(this.stopListening(this._view),delete this._view)},getRegion:function(t){return t?this.getView().getRegion(t):this._region},setView:function(t){return this._view===t?t:(this._view&&this.stopListening(this._view),this._view=t,this._isRunning&&this._proxyViewEvents(t),this._listenTo(this._view,"destroy",this._removeView),t)},getView:function(){return this._view||this._region&&this._region.currentView},showView:function(){for(var t,i=arguments.length>0&&void 0!==arguments[0]?arguments[0]:this._view,e=arguments.length,n=Array(e>1?e-1:0),s=1;s<e;s++)n[s-1]=arguments[s];return(t=this.getRegion()).show.apply(t,[i].concat(n)),i},showChildView:function(t,i){for(var e,n=arguments.length,s=Array(n>2?n-2:0),r=2;r<n;r++)s[r-2]=arguments[r];return(e=this.getView()).showChildView.apply(e,[t,i].concat(s)),i},getChildView:function(t){return this.getView().getChildView(t)}});i.extend(l.prototype,o,a,p,u);var g=["ViewClass","viewEventPrefix","viewEvents","viewTriggers","viewOptions","region"],c=n.MnObject.extend({ViewClass:n.View,constructor:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};this.mergeOptions(t,g),this.options=i.extend({},i.result(this,"options"),t),this._buildEventProxies(),this._initState(t),n.MnObject.call(this,t),this.delegateStateEvents()},_shouldDestroy:!0,showIn:function(t,i){return this.region=t,this.show(i),this},show:function(t){var i=this.getRegion();if(this._isShown)throw new Error("Component has already been shown in a region.");if(!i)throw new Error("Component has no defined region.");return this.triggerMethod("before:show"),this.renderView(t),this._isShown=!0,this.triggerMethod("show"),this.listenTo(i,"empty",this._destroy),this},getRegion:function(){return this.region},_getViewClass:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=this.ViewClass;if(n.prototype instanceof e.View||n===e.View)return n;if(i.isFunction(n))return n.call(this,t);throw new Error('"ViewClass" must be a view class or a function that returns a view class')},renderView:function(t){var i=this._getViewClass(t),e=this.mixinOptions(t),n=this.buildView(i,e);return this.currentView=n,this._proxyViewEvents(n),this.triggerMethod("before:render:view",n),this._shouldDestroy=!1,this.showView(n),this._shouldDestroy=!0,this.triggerMethod("render:view",n),this},showView:function(t){this.getRegion().show(t)},mixinOptions:function(t){var e=i.result(this,"viewOptions");return i.extend({state:this.getState().attributes},e,t)},buildView:function(t,i){return new t(i)},_destroy:function(){this._shouldDestroy&&n.MnObject.prototype.destroy.apply(this,arguments)},_emptyRegion:function(t){var i=this.getRegion();i&&(this.stopListening(i,"empty"),i.empty(t))},destroy:function(t){return this._emptyRegion(t),this._shouldDestroy=!0,this._destroy(t),this}});i.extend(c.prototype,o,u);var _="5.0.0-alpha.1",v={MixinState:s,VERSION:_,StateMixin:o,App:l,Component:c};t.MixinState=s,t.VERSION=_,t.StateMixin=o,t.App=l,t.Component=c,t.default=v}); | ||
!function(t,i){"object"==typeof exports&&"undefined"!=typeof module?i(exports,require("underscore"),require("backbone"),require("backbone.marionette")):"function"==typeof define&&define.amd?define(["exports","underscore","backbone","backbone.marionette"],i):i((t.Marionette=t.Marionette||{},t.Marionette.Toolkit=t.Marionette.Toolkit||{}),t._,t.Backbone,t.Marionette)}(this,function(t,i,e,n){"use strict";function s(t){var e=o;t.prototype.StateModel&&(e=i.omit(o,"StateModel")),i.extend(t.prototype,e)}i="default"in i?i.default:i,e="default"in e?e.default:e;var r=["StateModel","stateEvents"],o={StateModel:e.Model,initState:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return this._initState(t),this.delegateStateEvents(),this},_initState:function(t){this.mergeOptions(t,r),this._removeEventHandlers();var i=this._getStateModel(t);this._stateModel=new i(t.state),this._setEventHandlers()},delegateStateEvents:function(){return this.undelegateStateEvents(),this.bindEvents(this._stateModel,i.result(this,"stateEvents")),this},undelegateStateEvents:function(){return this.unbindEvents(this._stateModel),this},_setEventHandlers:function(){this.on("destroy",this._destroyState)},_removeEventHandlers:function(){this._stateModel&&(this.undelegateStateEvents(),this._stateModel.stopListening(),this.off("destroy",this._destroyState))},_getStateModel:function(t){if(this.StateModel.prototype instanceof e.Model||this.StateModel===e.Model)return this.StateModel;if(i.isFunction(this.StateModel))return this.StateModel.call(this,t);throw new Error('"StateModel" must be a model class or a function that returns a model class')},setState:function(){return this._stateModel.set.apply(this._stateModel,arguments)},resetStateDefaults:function(){var t=i.result(this._stateModel,"defaults");return this._stateModel.set(t)},getState:function(t){return t?this._stateModel.get.apply(this._stateModel,arguments):this._stateModel},toggleState:function(t,i){return arguments.length>1?this._stateModel.set(t,!!i):this._stateModel.set(t,!this._stateModel.get(t))},hasState:function(t){return this._stateModel.has(t)},_destroyState:function(){this._stateModel.stopListening()}},h=["childApps","childAppOptions"],a={_initChildApps:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};this._childApps={},this.mergeOptions(t,h);var e=this.childApps;e&&(i.isFunction(e)&&(e=e.call(this,t)),this.addChildApps(e))},_getChildStartOpts:function(t){var e=this,n=t._tkOpts||{},s={region:this.getRegion(n.regionName)};return i.each(n.getOptions,function(t){s[t]=e.getOption(t)}),s},_shouldRestart:function(t){return this._isRestarting&&i.result(t,"restartWithParent")},_startChildApps:function(){var t=this;i.each(this._childApps,function(e){return i.result(e,"startWithParent")?void e.start():void(t._shouldRestart(e)&&e.start())})},_stopChildApps:function(){var t=this;i.each(this._childApps,function(e){return i.result(e,"stopWithParent")?void e.stop():void(t._shouldRestart(e)&&e.stop())})},startChildApp:function(t,e){var n=this.getChildApp(t),s=this._getChildStartOpts(n);return n.start(i.extend(s,e))},stopChildApp:function(t,i){return this.getChildApp(t).stop(i)},_destroyChildApps:function(){i.each(this._childApps,function(t){i.result(t,"preventDestroy")||t.destroy()})},_buildAppFromObject:function(t){var e=t.AppClass,n=i.omit(t,"AppClass","regionName","getOptions"),s=this.buildApp(e,n);return s._tkOpts=i.pick(t,"regionName","getOptions"),s},_buildApp:function(t,e){return i.isFunction(t)?this.buildApp(t,e):i.isObject(t)?this._buildAppFromObject(t):void 0},buildApp:function(t,e){return e=i.extend({},this.childAppOptions,e),new t(e)},_ensureAppIsUnique:function(t){if(this._childApps[t])throw new Error('A child App with name "'+t+'" has already been added.')},addChildApps:function(t){i.each(t,i.bind(function(t,i){this.addChildApp(i,t)},this))},addChildApp:function(t,e,n){this._ensureAppIsUnique(t);var s=this._buildApp(e,n);if(!s)throw new Error("App build failed. Incorrect configuration.");return s._name=t,this._childApps[t]=s,s._on("destroy",i.partial(this._removeChildApp,t),this),this.isRunning()&&i.result(s,"startWithParent")&&s.start(),s},getName:function(){return this._name},getChildApps:function(){return i.clone(this._childApps)},getChildApp:function(t){return this._childApps[t]},_removeChildApp:function(t){delete this._childApps[t]._name,delete this._childApps[t]},removeChildApps:function(){var t=this.getChildApps();return i.each(this._childApps,i.bind(function(t,i){this.removeChildApp(i)},this)),t},removeChildApp:function(t,e){e=i.extend({},e);var n=this.getChildApp(t);if(n)return e.preventDestroy||i.result(n,"preventDestroy")?this._removeChildApp(t):n.destroy(),n}},p={_stopRunningEvents:function(){i.each(this._runningEvents,i.bind(function(t){this.off.apply(this,t)},this))},_stopRunningListeners:function(){i.each(this._runningListeningTo,i.bind(function(t){this.stopListening.apply(this,t)},this))},on:function(){return this._isRunning&&(this._runningEvents=this._runningEvents||[],this._runningEvents.push(arguments)),n.MnObject.prototype.on.apply(this,arguments)},_on:n.MnObject.prototype.on,listenTo:function(){return this._isRunning&&(this._runningListeningTo=this._runningListeningTo||[],this._runningListeningTo.push(arguments)),n.MnObject.prototype.listenTo.apply(this,arguments)},_listenTo:n.MnObject.prototype.listenTo,listenToOnce:function(){return this._isRunning&&(this._runningListeningTo=this._runningListeningTo||[],this._runningListeningTo.push(arguments)),n.MnObject.prototype.listenToOnce.apply(this,arguments)}},u={viewEventPrefix:!1,_buildEventProxies:function(){var t=i.result(this,"viewEvents")||{};this._viewEvents=this.normalizeMethods(t),this._viewTriggers=i.result(this,"viewTriggers")||{},this._viewEventPrefix=i.result(this,"viewEventPrefix")},_proxyViewEvents:function(t){this.listenTo(t,"all",this._childViewEventHandler)},_childViewEventHandler:function(t){for(var e=this._viewEvents,n=arguments.length,s=Array(n>1?n-1:0),r=1;r<n;r++)s[r-1]=arguments[r];i.isFunction(e[t])&&e[t].apply(this,s);var o=this._viewTriggers;i.isString(o[t])&&this.triggerMethod.apply(this,[o[t]].concat(s));var h=this._viewEventPrefix;if(h!==!1){var a=h+":"+t;this.triggerMethod.apply(this,[a].concat(s))}}},d=["startWithParent","restartWithParent","stopWithParent","startAfterInitialized","preventDestroy","StateModel","stateEvents","viewEventPrefix","viewEvents","viewTriggers"],l=n.Application.extend({_isRunning:!1,_isRestarting:!1,preventDestroy:!1,startAfterInitialized:!1,startWithParent:!1,stopWithParent:!0,restartWithParent:!1,constructor:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};this.mergeOptions(t,d),this.options=i.extend({},i.result(this,"options"),t),this._initChildApps(t),n.Application.call(this,t),i.result(this,"startAfterInitialized")&&this.start(t)},_ensureAppIsIntact:function(){if(this._isDestroyed)throw new Error("App has already been destroyed and cannot be used.")},isRunning:function(){return this._isRunning},isRestarting:function(){return this._isRestarting},start:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return this._ensureAppIsIntact(),this._isRunning?this:(t.region&&this.setRegion(t.region),t.view&&this.setView(t.view),this._initState(t),this._buildEventProxies(),this.triggerMethod("before:start",t),this._isRunning=!0,this._bindRunningEvents(),this._startChildApps(),this.triggerStart(t),this)},_bindRunningEvents:function(){this._region&&this._regionEventMonitor(),this._view&&this._proxyViewEvents(this._view),this.delegateStateEvents()},restart:function(){var t=this.getState().attributes;return this._isRestarting=!0,this.stop().start({state:t}),this._isRestarting=!1,this},triggerStart:function(t){this.triggerMethod("start",t)},stop:function(t){return this._isRunning?(this.triggerMethod("before:stop",t),this._stopChildApps(),this._isRunning=!1,this.triggerMethod("stop",t),this._stopRunningListeners(),this._stopRunningEvents(),this):this},destroy:function(){return this._isDestroyed?this:(this.stop(),this._removeView(),this._destroyChildApps(),n.Application.prototype.destroy.apply(this,arguments),this)},setRegion:function(t){return this._region&&this.stopListening(this._region),this._region=t,t.currentView&&this.setView(t.currentView),this._isRunning&&this._regionEventMonitor(),t},_regionEventMonitor:function(){this.listenTo(this._region,{"before:show":this._onBeforeShow,empty:this._onEmpty})},_onBeforeShow:function(t,i){this.setView(i)},_onEmpty:function(t,i){i===this._view&&this._removeView()},_removeView:function(){this._view&&(this.stopListening(this._view),delete this._view)},getRegion:function(t){return t?this.getView().getRegion(t):this._region},setView:function(t){return this._view===t?t:(this._view&&this.stopListening(this._view),this._view=t,this._isRunning&&this._proxyViewEvents(t),this._listenTo(this._view,"destroy",this._removeView),t)},getView:function(){return this._view||this._region&&this._region.currentView},showView:function(){for(var t,i=arguments.length>0&&void 0!==arguments[0]?arguments[0]:this._view,e=arguments.length,n=Array(e>1?e-1:0),s=1;s<e;s++)n[s-1]=arguments[s];return(t=this.getRegion()).show.apply(t,[i].concat(n)),i},showChildView:function(t,i){for(var e,n=arguments.length,s=Array(n>2?n-2:0),r=2;r<n;r++)s[r-2]=arguments[r];return(e=this.getView()).showChildView.apply(e,[t,i].concat(s)),i},getChildView:function(t){return this.getView().getChildView(t)}});i.extend(l.prototype,o,a,p,u);var g=["ViewClass","viewEventPrefix","viewEvents","viewTriggers","viewOptions","region"],c=n.MnObject.extend({ViewClass:n.View,constructor:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};this.mergeOptions(t,g),this.options=i.extend({},i.result(this,"options"),t),this._buildEventProxies(),this._initState(t),n.MnObject.call(this,t),this.delegateStateEvents()},_shouldDestroy:!0,showIn:function(t,i){return this.region=t,this.show(i),this},show:function(t){var i=this.getRegion();if(this._isShown)throw new Error("Component has already been shown in a region.");if(!i)throw new Error("Component has no defined region.");return this.triggerMethod("before:show"),this.renderView(t),this._isShown=!0,this.triggerMethod("show"),this.listenTo(i,"empty",this._destroy),this},getRegion:function(){return this.region},_getViewClass:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=this.ViewClass;if(n.prototype instanceof e.View||n===e.View)return n;if(i.isFunction(n))return n.call(this,t);throw new Error('"ViewClass" must be a view class or a function that returns a view class')},renderView:function(t){var i=this._getViewClass(t),e=this.mixinOptions(t),n=this.buildView(i,e);return this.currentView=n,this._proxyViewEvents(n),this.triggerMethod("before:render:view",n),this._shouldDestroy=!1,this.showView(n),this._shouldDestroy=!0,this.triggerMethod("render:view",n),this},showView:function(t){this.getRegion().show(t)},mixinOptions:function(t){var e=i.result(this,"viewOptions");return i.extend({state:this.getState().attributes},e,t)},buildView:function(t,i){return new t(i)},_destroy:function(){this._shouldDestroy&&n.MnObject.prototype.destroy.apply(this,arguments)},_emptyRegion:function(t){var i=this.getRegion();i&&(this.stopListening(i,"empty"),i.empty(t))},destroy:function(t){return this._emptyRegion(t),this._shouldDestroy=!0,this._destroy(t),this}});i.extend(c.prototype,o,u);var _="5.0.0-alpha.2",v={MixinState:s,VERSION:_,StateMixin:o,App:l,Component:c};t.MixinState=s,t.VERSION=_,t.StateMixin=o,t.App=l,t.Component=c,t.default=v}); | ||
//# sourceMappingURL=marionette.toolkit.min.js.map |
{ | ||
"name": "marionette.toolkit", | ||
"version": "5.0.0-alpha.1", | ||
"version": "5.0.0-alpha.2", | ||
"description": "A collection of opinionated Backbone.Marionette extensions for large scale application architecture.", | ||
@@ -5,0 +5,0 @@ "main": "./dist/marionette.toolkit.js", |
@@ -369,3 +369,5 @@ import _ from 'underscore'; | ||
*/ | ||
_onEmpty() { | ||
_onEmpty(region, view) { | ||
if(view !== this._view) return; | ||
this._removeView(); | ||
@@ -372,0 +374,0 @@ }, |
@@ -66,2 +66,12 @@ import _ from 'underscore'; | ||
/** | ||
* Determines if `childApps` should restart | ||
* | ||
* @private | ||
* @method _shouldRestart | ||
*/ | ||
_shouldRestart(childApp) { | ||
return this._isRestarting && _.result(childApp, 'restartWithParent'); | ||
}, | ||
/** | ||
* Starts `childApps` if allowed by child | ||
@@ -73,8 +83,11 @@ * | ||
_startChildApps() { | ||
const shouldStartOption = this._isRestarting ? 'restartWithParent' : 'startWithParent'; | ||
_.each(this._childApps, childApp => { | ||
if(!_.result(childApp, shouldStartOption)) return; | ||
if(_.result(childApp, 'startWithParent')) { | ||
childApp.start(); | ||
return; | ||
} | ||
const opts = this._getChildStartOpts(childApp); | ||
childApp.start(opts); | ||
if(this._shouldRestart(childApp)) { | ||
childApp.start(); | ||
} | ||
}); | ||
@@ -90,7 +103,11 @@ }, | ||
_stopChildApps() { | ||
const shouldStopOption = this._isRestarting ? 'restartWithParent' : 'stopWithParent'; | ||
_.each(this._childApps, function(childApp) { | ||
if(_.result(childApp, shouldStopOption)) { | ||
_.each(this._childApps, childApp => { | ||
if(_.result(childApp, 'stopWithParent')) { | ||
childApp.stop(); | ||
return; | ||
} | ||
if(this._shouldRestart(childApp)) { | ||
childApp.stop(); | ||
} | ||
}); | ||
@@ -97,0 +114,0 @@ }, |
@@ -142,3 +142,6 @@ function createNewApp(startWParent, stopWParent, prevDestroy) { | ||
const childApps = { | ||
cA1: Marionette.Toolkit.App | ||
cA1: { | ||
AppClass: Marionette.Toolkit.App, | ||
stopWithParent: false | ||
} | ||
}; | ||
@@ -145,0 +148,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
495761
4770