From a76b299405afd7d239b15cc6196b5eb27d9d291b Mon Sep 17 00:00:00 2001 From: Paul Falgout Date: Fri, 30 Aug 2019 16:00:48 +0900 Subject: [PATCH] Bump and build v6.1.0 --- CHANGELOG.md | 9 +++++++++ dist/marionette.toolkit.esm.js | 20 ++++++++++++++------ dist/marionette.toolkit.js | 22 +++++++++++++++------- dist/marionette.toolkit.js.map | 2 +- dist/marionette.toolkit.min.js | 4 ++-- dist/marionette.toolkit.min.js.map | 2 +- package.json | 2 +- 7 files changed, 43 insertions(+), 18 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a6f98ee..1a3eaee 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,12 @@ +#### v6.1.0 + +* **Features** + * `Component.showIn` now supports passing `regionOptions` + +* **Fixes** + * When an app is stopped, the running events cache is now cleared correctly + * `viewEvents` now works if a view is shown during `onBeforeShow` + #### v6.0.1 * Add .npmignore diff --git a/dist/marionette.toolkit.esm.js b/dist/marionette.toolkit.esm.js index c7ff427..2f662c9 100644 --- a/dist/marionette.toolkit.esm.js +++ b/dist/marionette.toolkit.esm.js @@ -621,6 +621,8 @@ var EventListenersMixin = { _.each(this._runningEvents, _.bind(function (args) { this.off.apply(this, args); }, this)); + + this._runningEvents = []; }, /** @@ -633,6 +635,8 @@ var EventListenersMixin = { _.each(this._runningListeningTo, _.bind(function (args) { this.stopListening.apply(this, args); }, this)); + + this._runningListeningTo = []; }, /** @@ -1231,15 +1235,18 @@ var App = Application.extend({ * @returns {View} */ showView: function showView() { - var _this$getRegion; - var view = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : this._view; + var region = this.getRegion(); for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) { args[_key - 1] = arguments[_key]; } - (_this$getRegion = this.getRegion()).show.apply(_this$getRegion, [view].concat(args)); + region.show.apply(region, [view].concat(args)); + + if (!this.isRunning()) { + this.setView(region.currentView); + } return view; }, @@ -1335,11 +1342,12 @@ var Component = Application.extend({ * @memberOf Component * @param {Marionette.Region} region - The region for the component * @param {Object} [viewOptions] - Options hash mixed into the instantiated ViewClass. + * @param {Object} [regionOptions] - Options hash mixed into the instantiated region. * @returns {Component} */ - showIn: function showIn(region, viewOptions) { + showIn: function showIn(region, viewOptions, regionOptions) { this._region = region; - this.show(viewOptions); + this.show(viewOptions, regionOptions); return this; }, @@ -1527,7 +1535,7 @@ var Component = Application.extend({ _.extend(Component.prototype, StateMixin, ViewEventsMixin); -var version = "6.0.1"; +var version = "6.1.0"; /** * @module Toolkit diff --git a/dist/marionette.toolkit.js b/dist/marionette.toolkit.js index fe8ba1b..8c08338 100644 --- a/dist/marionette.toolkit.js +++ b/dist/marionette.toolkit.js @@ -1,6 +1,6 @@ /** * marionette.toolkit - A collection of opinionated Backbone.Marionette extensions for large scale application architecture. - * @version v6.0.1 + * @version v6.1.0 * @link https://github.com/RoundingWellOS/marionette.toolkit * @license MIT */ @@ -637,6 +637,8 @@ _.each(this._runningEvents, _.bind(function (args) { this.off.apply(this, args); }, this)); + + this._runningEvents = []; }, /** @@ -649,6 +651,8 @@ _.each(this._runningListeningTo, _.bind(function (args) { this.stopListening.apply(this, args); }, this)); + + this._runningListeningTo = []; }, /** @@ -1247,15 +1251,18 @@ * @returns {View} */ showView: function showView() { - var _this$getRegion; - var view = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : this._view; + var region = this.getRegion(); for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) { args[_key - 1] = arguments[_key]; } - (_this$getRegion = this.getRegion()).show.apply(_this$getRegion, [view].concat(args)); + region.show.apply(region, [view].concat(args)); + + if (!this.isRunning()) { + this.setView(region.currentView); + } return view; }, @@ -1351,11 +1358,12 @@ * @memberOf Component * @param {Marionette.Region} region - The region for the component * @param {Object} [viewOptions] - Options hash mixed into the instantiated ViewClass. + * @param {Object} [regionOptions] - Options hash mixed into the instantiated region. * @returns {Component} */ - showIn: function showIn(region, viewOptions) { + showIn: function showIn(region, viewOptions, regionOptions) { this._region = region; - this.show(viewOptions); + this.show(viewOptions, regionOptions); return this; }, @@ -1543,7 +1551,7 @@ _.extend(Component.prototype, StateMixin, ViewEventsMixin); - var version = "6.0.1"; + var version = "6.1.0"; /** * @module Toolkit diff --git a/dist/marionette.toolkit.js.map b/dist/marionette.toolkit.js.map index 41445dc..d93750a 100644 --- a/dist/marionette.toolkit.js.map +++ b/dist/marionette.toolkit.js.map @@ -1 +1 @@ -{"version":3,"file":"marionette.toolkit.js","sources":["../src/mixins/state.js","../src/mixins/child-apps.js","../src/mixins/event-listeners.js","../src/mixins/view-events.js","../src/app.js","../src/component.js","../src/marionette.toolkit.js"],"sourcesContent":["import _ from 'underscore';\nimport Backbone from 'backbone';\n\nconst ClassOptions = [\n 'StateModel',\n 'stateEvents'\n];\n\n/**\n * This provides methods used for keeping state using a Backbone.Model. It's meant to\n * be used with either a Marionette.MnObject or Backbone.View.\n *\n * @mixin\n */\nexport default {\n\n /**\n * The model class for _stateModel.\n * @type {Backbone.Model}\n * @default Backbone.Model\n */\n StateModel: Backbone.Model,\n\n /**\n * @public\n * @method initState\n * @param {Object} [options] - Settings for the StateMixin.\n * @param {Object} [options.stateEvents] - Event hash bound from _stateModel to StateMixin.\n * @param {Backbone.Model} [options.StateModel] - Model class for _stateModel.\n */\n initState(options = {}) {\n this._initState(options);\n this.delegateStateEvents();\n\n return this;\n },\n\n /**\n * @private\n * @method _initState\n * @param {Object} [options] - Settings for the StateMixin.\n */\n _initState(options) {\n // Make defaults available to this\n this.mergeOptions(options, ClassOptions);\n\n // Remove event handlers from previous state\n this._removeEventHandlers();\n\n const StateModel = this._getStateModel(options);\n\n this._stateModel = new StateModel(options.state);\n\n this._setEventHandlers();\n },\n\n /**\n * Bind events from the _stateModel defined in stateEvents hash\n *\n * @public\n * @method delegateStateEvents\n */\n delegateStateEvents() {\n this.undelegateStateEvents();\n this.bindEvents(this._stateModel, _.result(this, 'stateEvents'));\n\n return this;\n },\n\n /**\n * Unbind all entity events on _stateModel\n *\n * @public\n * @method undelegateStateEvents\n */\n undelegateStateEvents() {\n this.unbindEvents(this._stateModel);\n\n return this;\n },\n\n /**\n * Setup destroy event handle\n *\n * @private\n * @method _setEventHandlers\n */\n _setEventHandlers() {\n this.on('destroy', this._destroyState);\n },\n\n /**\n * Clean up destroy event handler, remove any listeners on _stateModel\n *\n * @private\n * @method _removeEventHandlers\n */\n _removeEventHandlers() {\n if (!this._stateModel) {return;}\n\n this.undelegateStateEvents();\n this._stateModel.stopListening();\n this.off('destroy', this._destroyState);\n },\n\n\n /**\n * Get the StateMixin StateModel class.\n * Checks if the `StateModel` is a model class (the common case)\n * Then check if it's a function (which we assume that returns a model class)\n *\n * @private\n * @method _getStateModel\n * @param {Object} [options] - Options that can be used to determine the StateModel.\n * @returns {Backbone.Model}\n */\n _getStateModel(options) {\n if (this.StateModel.prototype instanceof Backbone.Model || this.StateModel === Backbone.Model) {\n return this.StateModel;\n } else if (_.isFunction(this.StateModel)) {\n return this.StateModel.call(this, options);\n }\n\n throw new Error('\"StateModel\" must be a model class or a function that returns a model class');\n },\n\n /**\n * Set a property on the _stateModel.\n *\n * @public\n * @method setState\n * @param {String|Object} key - Attribute name or Hash of any number of key value pairs.\n * @param {*} [value] - Attribute value if key is String, replaces options param otherwise.\n * @param {Object} [options] - Backbone.Model options.\n * @returns {Backbone.Model} - The _stateModel\n */\n setState() {\n return this._stateModel.set.apply(this._stateModel, arguments);\n },\n\n\n /**\n * Reset _stateModel to defined defaults\n *\n * @public\n * @method resetStateDefaults\n * @param {Object} [newState] - Hash of any number of key value pairs.\n * @returns {Backbone.Model|*} - The _stateModel or the attribute value of the _stateModel\n */\n resetStateDefaults() {\n const defaults = _.result(this._stateModel, 'defaults');\n\n return this._stateModel.set(defaults);\n },\n\n /**\n * Get a property from the _stateModel, or return the _stateModel\n *\n * @public\n * @method getState\n * @param {String} [attr] - Attribute name of stateModel.\n * @returns {Backbone.Model|*} - The _stateModel or the attribute value of the _stateModel\n */\n getState(attr) {\n if (!attr) {\n return this._stateModel;\n }\n\n return this._stateModel.get.apply(this._stateModel, arguments);\n },\n\n /**\n * Toggle a property on the _stateModel.\n *\n * @public\n * @method toggleState\n * @param {String} attr - Attribute name of stateModel.\n * @param {val} [value] - Attribute value.\n * @returns {Backbone.Model} - The _stateModel or attribute value.\n */\n toggleState(attr, val) {\n if (arguments.length > 1) {return this._stateModel.set(attr, !!val);}\n\n return this._stateModel.set(attr, !this._stateModel.get(attr));\n },\n\n /**\n * Check if _stateModel has a property\n *\n * @public\n * @method hasState\n * @param {String} [attr] - Attribute name of stateModel.\n * @returns {Boolean}\n */\n hasState(attr) {\n return this._stateModel.has(attr);\n },\n\n /**\n * Clean up any listeners on the _stateModel.\n *\n * @private\n * @method _destroyState\n */\n _destroyState() {\n this._stateModel.stopListening();\n }\n};\n","import _ from 'underscore';\n\nconst ClassOptions = [\n 'childApps',\n 'childAppOptions'\n];\n\n/**\n * This provides methods used for \"App Manager\" functionality - the adding and removing child `App`s. It's not meant to\n * be used directly.\n *\n * @mixin\n */\nexport default {\n\n /**\n * @private\n * @method _initChildApps\n * @constructs ChildApps\n * @param {Object} [options] - Settings for the ChildApps.\n * @param {Object} [options.childApps] - Hash for setting up child apps.\n * @param {Object} [options.childAppOptions] - Hash of options passed to every child app.\n *\n * ```js\n * childApps: {\n * appName: {\n * AppClass: MyChildAppClass,\n * fooOption: true,\n * startWithParent: true\n * },\n * barApp: MyOtherChildAppClass\n * }\n * ```\n */\n _initChildApps(options = {}) {\n this._childApps = {};\n\n this.mergeOptions(options, ClassOptions);\n\n let childApps = this.childApps;\n\n if (childApps) {\n if (_.isFunction(childApps)) {\n childApps = childApps.call(this, options);\n }\n\n this.addChildApps(childApps);\n }\n },\n\n /**\n * Finds `regionName` and `getOptions` for the childApp\n *\n * @private\n * @method _getChildStartOpts\n */\n _getChildStartOpts(childApp) {\n const tkOpts = childApp._tkOpts || {};\n\n const opts = {\n region: this.getRegion(tkOpts.regionName)\n };\n\n _.each(tkOpts.getOptions, opt => {\n opts[opt] = this.getOption(opt);\n });\n\n return opts;\n },\n\n /**\n * Starts a `childApp`\n *\n * @private\n * @method _startChildApp\n */\n _startChildApp(childApp, options) {\n const opts = this._getChildStartOpts(childApp);\n return childApp.start(_.extend(opts, options));\n },\n\n /**\n * Handles explicit boolean values of restartWithParent\n * restartWithParent === false does nothing\n *\n * @private\n * @method _shouldStartWithRestart\n */\n _shouldActWithRestart(childApp, action) {\n if (!this._isRestarting) {return true;}\n const restartWithParent = _.result(childApp, 'restartWithParent');\n if (restartWithParent === true) {return true;}\n if (restartWithParent !== false && _.result(childApp, action)) {return true;}\n },\n\n /**\n * Starts `childApps` if allowed by child\n *\n * @private\n * @method _startChildApps\n */\n _startChildApps() {\n const action = 'startWithParent';\n _.each(this._childApps, childApp => {\n if (!this._shouldActWithRestart(childApp, action)) {return;}\n if (!this._isRestarting && !_.result(childApp, action)) {return;}\n this._startChildApp(childApp);\n });\n },\n\n /**\n * Stops `childApps` if allowed by child\n *\n * @private\n * @method _stopChildApps\n */\n _stopChildApps() {\n const action = 'stopWithParent';\n _.each(this._childApps, childApp => {\n if (!this._shouldActWithRestart(childApp, action)) {return;}\n if (!this._isRestarting && !_.result(childApp, action)) {return;}\n childApp.stop();\n });\n },\n\n /**\n * Starts `childApp`\n *\n * @param {String} appName - Name of childApp to start\n * @param {Object} options - Start options for app\n * @public\n * @method startChildApp\n */\n startChildApp(appName, options) {\n const childApp = this.getChildApp(appName);\n return this._startChildApp(childApp, options);\n },\n\n /**\n * Stops `childApp`\n *\n * @param {String} appName - Name of childApp to stop\n * @param {Object} options - Stop options for app\n * @public\n * @method stopChildApp\n */\n stopChildApp(appName, options) {\n return this.getChildApp(appName).stop(options);\n },\n\n /**\n * Destroys `childApps` if allowed by child\n *\n * @private\n * @method _destroyChildApps\n */\n _destroyChildApps() {\n _.each(this._childApps, function(childApp) {\n if (!_.result(childApp, 'preventDestroy')) {\n childApp.destroy();\n }\n });\n },\n\n /**\n * Internal helper to instantiate and `App` from on `Object`\n *\n * @private\n * @method _buildAppFromObject\n * @param {Object} appConfig - `AppClass` and any other option for the `App`\n * @returns {App}\n */\n _buildAppFromObject(appConfig) {\n const AppClass = appConfig.AppClass;\n const options = _.omit(appConfig, 'AppClass', 'regionName', 'getOptions');\n\n const app = this.buildApp(AppClass, options);\n\n app._tkOpts = _.pick(appConfig, 'regionName', 'getOptions');\n\n return app;\n },\n\n /**\n * Helper for building an App and return it\n *\n * @private\n * @method _buildApp\n * @param {App} AppClass - An App Class\n * @param {Object} AppClass - Optionally passed as an appConfig Object\n * @param {Object} [options] - options for the AppClass\n * @returns {App}\n */\n _buildApp(AppClass, options) {\n if (_.isFunction(AppClass)) {\n return this.buildApp(AppClass, options);\n }\n if (_.isObject(AppClass)) {\n return this._buildAppFromObject(AppClass);\n }\n },\n\n /**\n * Build an App and return it\n * Override for dynamic App building\n *\n * @public\n * @method buildApp\n * @param {App} [AppClass] - An App Class\n * @param {Object} [options] - options for the AppClass\n * @returns {App}\n */\n buildApp(AppClass, options) {\n // options on childApp definition supersede childAppOptions\n options = _.extend({}, this.childAppOptions, options);\n\n return new AppClass(options);\n },\n\n /**\n * Internal helper to verify `appName` is unique and not in use\n *\n * @private\n * @method _ensureAppIsUnique\n * @param {String} appName - Name of app to test\n * @throws DuplicateChildAppError - Thrown if `App` already has an `appName` registered\n */\n _ensureAppIsUnique(appName) {\n if (this._childApps[appName]) {\n throw new Error(`A child App with name \"${ appName }\" has already been added.`);\n }\n },\n\n /**\n * Add child `App`s to this `App`\n *\n * @public\n * @method addChildApps\n * @param {Object} childApps - Hash of names and `AppClass` or `appConfig`\n */\n addChildApps(childApps) {\n _.each(childApps, _.bind(function(childApp, appName) {\n this.addChildApp(appName, childApp);\n }, this));\n },\n\n /**\n * Build's childApp and registers it with this App\n * Starts the childApp, if this app is running and child is `startWithParent`\n *\n * @public\n * @method addChildApp\n * @param {String} appName - Name of App to register\n * @param {App} AppClass - An App Class\n * @param {Object} AppClass - Optionally passed as an appConfig Object\n * @param {Object} [options] - options for the AppClass\n * @throws AddChildAppError - Thrown if no childApp could be built from params\n * @returns {App}\n */\n addChildApp(appName, AppClass, options) {\n this._ensureAppIsUnique(appName);\n\n const childApp = this._buildApp(AppClass, options);\n\n if (!childApp) {\n throw new Error('App build failed. Incorrect configuration.');\n }\n\n childApp._name = appName;\n\n this._childApps[appName] = childApp;\n\n // When the app is destroyed remove the cached app.\n // Listener setup relative to the childApp's running state (using _on)\n childApp._on('destroy', _.partial(this._removeChildApp, appName), this);\n\n if (this.isRunning() && _.result(childApp, 'startWithParent')) {\n this._startChildApp(childApp);\n }\n\n return childApp;\n },\n\n /**\n * Returns registered child `App`s name\n *\n * @public\n * @method getName\n * @returns {String}\n */\n getName() {\n return this._name;\n },\n\n\n /**\n * Returns registered child `App`s array\n *\n * @public\n * @method getChildApps\n * @returns {Array}\n */\n getChildApps() {\n return _.clone(this._childApps);\n },\n\n /**\n * Returns registered child `App`\n *\n * @public\n * @method getChildApp\n * @param {String} appName - Name of App to retrieve\n * @returns {App}\n */\n getChildApp(appName) {\n return this._childApps[appName];\n },\n\n /**\n * Internal helper. Unregisters child `App`\n *\n * @private\n * @method _removeChildApp\n * @param {String} appName - Name of App to unregister\n * @returns {App}\n */\n _removeChildApp(appName) {\n delete this._childApps[appName]._name;\n delete this._childApps[appName];\n },\n\n /**\n * Removes all childApps and returns them.\n * The return is useful if any app is using `preventDestroy`\n *\n * @public\n * @method removeChildApps\n * @returns {Array}\n */\n removeChildApps() {\n const childApps = this.getChildApps();\n\n _.each(this._childApps, _.bind(function(childApp, appName) {\n this.removeChildApp(appName);\n }, this));\n\n return childApps;\n },\n\n /**\n * Destroys or removes registered child `App` by name\n * depending on `preventDestroy`\n *\n * @public\n * @method removeChildApp\n * @param {String} appName - Name of App to destroy\n * @param {Object} [options.preventDestroy] - Flag to remove but prevent App destroy\n * @returns {App}\n */\n removeChildApp(appName, options) {\n options = _.extend({}, options);\n\n const childApp = this.getChildApp(appName);\n\n if (!childApp) {\n return;\n }\n\n // if preventDestroy simply unregister the child app\n if (options.preventDestroy || _.result(childApp, 'preventDestroy')) {\n this._removeChildApp(appName);\n } else {\n childApp.destroy();\n }\n\n return childApp;\n }\n};\n","import _ from 'underscore';\nimport { MnObject } from 'backbone.marionette';\n\n/**\n * This provides methods used for registering events while App is running and cleans them up at `onStop`. It's not meant to\n * be used directly.\n *\n * @mixin\n */\n\nexport default {\n /**\n * Internal method to stop any registered events.\n *\n * @private\n * @method _stopRunningEvents\n */\n _stopRunningEvents() {\n _.each(this._runningEvents, _.bind(function(args) {\n this.off.apply(this, args);\n }, this));\n },\n\n /**\n * Internal method to stop any registered listeners.\n *\n * @private\n * @method _stopRunningListeners\n */\n _stopRunningListeners() {\n _.each(this._runningListeningTo, _.bind(function(args) {\n this.stopListening.apply(this, args);\n }, this));\n },\n\n /**\n * Overrides `Backbone.Event.on()`\n * If this `App` is running it will register the event for removal `onStop`\n *\n * @public\n * @method on\n * @returns {EventListeners}\n */\n on() {\n if (this._isRunning) {\n this._runningEvents = (this._runningEvents || []);\n this._runningEvents.push(arguments);\n }\n\n return MnObject.prototype.on.apply(this, arguments);\n },\n\n /**\n * Keep a copy of non-running on for internal use\n *\n * @private\n * @method _on\n * @returns {EventListeners}\n */\n _on: MnObject.prototype.on,\n\n /**\n * Overrides `Backbone.Event.listenTo()`\n * If this `App` is running it will register the listener for removal `onStop`\n *\n * @public\n * @method listenTo\n * @returns {EventListeners}\n */\n listenTo() {\n if (this._isRunning) {\n this._runningListeningTo = (this._runningListeningTo || []);\n this._runningListeningTo.push(arguments);\n }\n return MnObject.prototype.listenTo.apply(this, arguments);\n },\n\n /**\n * Keep a copy of non-running on for internal use\n *\n * @private\n * @method _listenTo\n * @returns {EventListeners}\n */\n _listenTo: MnObject.prototype.listenTo,\n\n /**\n * Overrides `Backbone.Event.listenToOnce()`\n * If this `App` is running it will register the listener for removal `onStop`\n *\n * @public\n * @method listenToOnce\n * @returns {EventListeners}\n */\n listenToOnce() {\n if (this._isRunning) {\n this._runningListeningTo = (this._runningListeningTo || []);\n this._runningListeningTo.push(arguments);\n }\n\n return MnObject.prototype.listenToOnce.apply(this, arguments);\n }\n};\n","import _ from 'underscore';\n\nexport default {\n /**\n * Used as the prefix for events forwarded from\n * the component's view to the component\n * @type {String}\n * @default false\n */\n viewEventPrefix: false,\n\n /**\n * Constructs hashes and options for view event proxy\n *\n * @private\n * @method _buildEventProxies\n */\n _buildEventProxies() {\n const viewEvents = _.result(this, 'viewEvents') || {};\n this._viewEvents = this.normalizeMethods(viewEvents);\n this._viewTriggers = _.result(this, 'viewTriggers') || {};\n this._viewEventPrefix = _.result(this, 'viewEventPrefix');\n },\n\n /**\n * Proxies the ViewClass's viewEvents to the Component itself\n * Similar to CollectionView childEvents\n * (http://marionettejs.com/docs/v2.3.2/marionette.collectionview.html#collectionviews-childevents)\n *\n * @private\n * @method _proxyViewEvents\n * @param {Mn.View|Mn.CollectionView} view -\n * The instantiated ViewClass.\n */\n _proxyViewEvents(view) {\n this.listenTo(view, 'all', this._childViewEventHandler);\n },\n\n /**\n * Event handler for view proxy\n * Similar to CollectionView childEvents\n * (http://marionettejs.com/docs/v2.3.2/marionette.collectionview.html#collectionviews-childevents)\n *\n * @private\n * @method _childViewEventHandler\n * @param {String} - event name\n */\n _childViewEventHandler(eventName, ...args) {\n const viewEvents = this._viewEvents;\n\n if (_.isFunction(viewEvents[eventName])) {\n viewEvents[eventName].apply(this, args);\n }\n\n // use the parent view's proxyEvent handlers\n const viewTriggers = this._viewTriggers;\n\n // Call the event with the proxy name on the parent layout\n if (_.isString(viewTriggers[eventName])) {\n this.triggerMethod(viewTriggers[eventName], ...args);\n }\n\n const prefix = this._viewEventPrefix;\n\n if (prefix !== false) {\n const viewEventName = `${ prefix }:${ eventName }`;\n\n this.triggerMethod(viewEventName, ...args);\n }\n }\n};\n","import _ from 'underscore';\nimport { Application } from 'backbone.marionette';\nimport StateMixin from './mixins/state';\nimport ChildAppsMixin from './mixins/child-apps';\nimport EventListenersMixin from './mixins/event-listeners';\nimport ViewEventsMixin from './mixins/view-events';\n\nconst ClassOptions = [\n 'startWithParent',\n 'restartWithParent',\n 'stopWithParent',\n 'startAfterInitialized',\n 'preventDestroy',\n 'StateModel',\n 'stateEvents',\n 'viewEventPrefix',\n 'viewEvents',\n 'viewTriggers'\n];\n\n/**\n * Marionette.Application with an `initialize` / `start` / `stop` / `destroy` lifecycle.\n *\n * @public\n * @class App\n * @memberOf Toolkit\n * @memberOf Marionette\n */\nconst App = Application.extend({\n\n /**\n * Internal flag indiciate when `App` has started but has not yet stopped.\n *\n * @private\n * @type {Boolean}\n * @default false\n */\n _isRunning: false,\n\n /**\n * Internal flag indiciate when `App` is in the process of stopping then starting.\n *\n * @private\n * @type {Boolean}\n * @default false\n */\n _isRestarting: false,\n\n /**\n * Set to true if a parent `App` should not be able to destroy this `App`.\n *\n * @type {Boolean|Function}\n * @default false\n */\n preventDestroy: false,\n\n /**\n * Set to true if `App` should be started after it is initialized.\n *\n * @type {Boolean|Function}\n * @default false\n */\n startAfterInitialized: false,\n\n /**\n * Set to true if `App` should be started after its parent starts.\n *\n * @type {Boolean|Function}\n * @default false\n */\n startWithParent: false,\n\n /**\n * Set to false if `App` should not stop after its parent stops.\n *\n * @type {Boolean|Function}\n * @default true\n */\n stopWithParent: true,\n\n\n /**\n * Set this to determine if a parent `App` should maintain the child's\n * lifecycle during a restart.\n *\n * @type {Boolean|Function}\n * @default null\n */\n restartWithParent: null,\n\n /**\n * @public\n * @constructs App\n * @param {Object} [options] - Settings for the App.\n * @param {Boolean} [options.startWithParent]\n * @param {Boolean} [options.restartWithParent]\n * @param {Boolean} [options.stopWithParent]\n * @param {Boolean} [options.startAfterInitialized]\n * @param {Boolean} [options.preventDestroy]\n * @param {Object} [options.state] - Attributes to set on the state model.\n */\n constructor(options = {}) {\n this.mergeOptions(options, ClassOptions);\n\n this.options = _.extend({}, _.result(this, 'options'), options);\n\n // ChildAppsMixin\n this._initChildApps(options);\n\n Application.call(this, options);\n\n if (_.result(this, 'startAfterInitialized')) {\n this.start(options);\n }\n },\n\n /**\n * Internal helper to verify if `App` has been destroyed\n *\n * @private\n * @method _ensureAppIsIntact\n * @memberOf App\n * @throws AppDestroyedError - Thrown if `App` has already been destroyed\n */\n _ensureAppIsIntact() {\n if (this._isDestroyed) {\n throw new Error('App has already been destroyed and cannot be used.');\n }\n },\n\n /**\n * Gets the value of internal `_isRunning` flag\n *\n * @public\n * @method isRunning\n * @memberOf App\n * @returns {Boolean}\n */\n isRunning() {\n return this._isRunning;\n },\n\n /**\n * Gets the value of internal `_isRestarting` flag\n *\n * @public\n * @method isRestarting\n * @memberOf App\n * @returns {Boolean}\n */\n isRestarting() {\n return this._isRestarting;\n },\n\n /**\n * Sets the app lifecycle to running.\n *\n * @public\n * @method start\n * @memberOf App\n * @param {Object} [options] - Settings for the App passed through to events\n * @event App#before:start - passes options\n * @returns {App}\n */\n start(options = {}) {\n this._ensureAppIsIntact();\n\n if (this._isRunning) {\n return this;\n }\n\n if (options.region) {\n this.setRegion(options.region);\n }\n\n if (options.view) {\n this.setView(options.view);\n }\n\n // StateMixin\n this._initState(options);\n\n // ViewEventMixin\n this._buildEventProxies();\n\n this.triggerMethod('before:start', options);\n\n this._isRunning = true;\n\n this._bindRunningEvents();\n\n this.triggerStart(options);\n\n return this;\n },\n\n /**\n * Sets up region, view, and state events.\n * To only be called after `isRunning` is true\n *\n * @private\n * @method _bindRunningEvents\n * @memberOf App\n */\n _bindRunningEvents() {\n if (this._region) {\n this._regionEventMonitor();\n }\n\n if (this._view) {\n this._proxyViewEvents(this._view);\n }\n\n // StateMixin\n this.delegateStateEvents();\n },\n\n /**\n * Sets the app lifecycle to not running\n * then sets the app lifecycle to running with ending state\n *\n * @public\n * @method restart\n * @memberOf App\n * @returns {App}\n */\n restart() {\n const state = this.getState().attributes;\n\n this._isRestarting = true;\n this.stop().start({ state });\n this._isRestarting = false;\n\n return this;\n },\n\n /**\n * Starts children and triggers start event\n * For calling within `triggerStart`\n *\n * @public\n * @method finallyStart\n * @memberOf App\n * @event App#start - passes any arguments\n * @returns\n */\n finallyStart() {\n this._startChildApps();\n this.triggerMethod('start', ...arguments);\n },\n\n /**\n * Triggers start event via finallyStart.\n * Override to introduce async start\n *\n * @public\n * @method triggerStart\n * @memberOf App\n * @param {Object} [options] - Settings for the App passed through to events\n * @returns\n */\n triggerStart(options) {\n this.finallyStart(options);\n },\n\n /**\n * Sets the app lifecycle to not running.\n * Removes any listeners added during the running state\n *\n * @public\n * @method stop\n * @memberOf App\n * @param {Object} [options] - Settings for the App passed through to events\n * @event App#before:stop - passes options\n * @event App#stop - passes options\n * @returns {App}\n */\n stop(options) {\n if (!this._isRunning) {\n return this;\n }\n\n this.triggerMethod('before:stop', options);\n\n this._stopChildApps();\n\n this._isRunning = false;\n\n this.triggerMethod('stop', options);\n\n // Running events are cleaned up after stop so that\n // `stop` event handlers still fire\n this._stopRunningListeners();\n this._stopRunningEvents();\n\n return this;\n },\n\n /**\n * Stops the `App` and sets it destroyed.\n *\n * @public\n * @method destroy\n * @memberOf App\n */\n destroy() {\n if (this._isDestroyed) {\n return this;\n }\n\n this.stop();\n\n this._removeView();\n\n this._destroyChildApps();\n\n Application.prototype.destroy.apply(this, arguments);\n\n return this;\n },\n\n /**\n * Set the Application's Region\n *\n * @public\n * @method setRegion\n * @memberOf App\n * @param {Region} [region] - Region to use with the app\n * @returns {Region}\n */\n setRegion(region) {\n if (this._region) {\n this.stopListening(this._region);\n }\n\n this._region = region;\n\n if (region.currentView) {\n this.setView(region.currentView);\n }\n\n if (this._isRunning) {\n this._regionEventMonitor();\n }\n\n return region;\n },\n\n /**\n * Monitors the apps region before:show event so the region's view\n * is available to the app\n *\n * @private\n * @method _regionEventMonitor\n * @memberOf App\n */\n _regionEventMonitor() {\n this.listenTo(this._region, {\n 'before:show': this._onBeforeShow,\n 'empty': this._onEmpty\n });\n },\n\n /**\n * Region monitor handler which sets the app's view to the region's view\n *\n * @private\n * @method _onBeforeShow\n * @memberOf App\n */\n _onBeforeShow(region, view) {\n this.setView(view);\n },\n\n /**\n * Region monitor handler which empties the region's view\n *\n * @private\n * @method _onEmpty\n * @memberOf App\n */\n _onEmpty(region, view) {\n if (view !== this._view) {return;}\n\n this._removeView();\n },\n\n /**\n * Region monitor handler which deletes the region's view and listeners to view\n *\n * @private\n * @method _removeView\n * @memberOf App\n */\n _removeView() {\n if (this._view) {\n this.stopListening(this._view);\n delete this._view;\n }\n },\n\n /**\n * Get the Application's Region or\n * Get a region from the Application's View\n *\n * @public\n * @method getRegion\n * @memberOf App\n * @param {String} [regionName] - Optional regionName to get from the view\n * @returns {Region}\n */\n getRegion(regionName) {\n if (!regionName) {\n return this._region;\n }\n\n return this.getView().getRegion(regionName);\n },\n\n /**\n * Set the Application's View\n *\n * @public\n * @method setView\n * @memberOf App\n * @param {View} [view] - View to use with the app\n * @returns {View}\n */\n setView(view) {\n if (this._view === view) {\n return view;\n }\n\n if (this._view) {\n this.stopListening(this._view);\n }\n\n this._view = view;\n\n // ViewEventsMixin\n if (this._isRunning) {\n this._proxyViewEvents(view);\n }\n\n // Internal non-running listener\n this._listenTo(this._view, 'destroy', this._removeView);\n\n return view;\n },\n\n /**\n * Get the Application's View\n *\n * @public\n * @method getView\n * @memberOf App\n * @returns {View}\n */\n getView() {\n return this._view || this._region && this._region.currentView;\n },\n\n /**\n * Shows a view in the Application's region\n *\n * @public\n * @method showView\n * @param {View} view - Child view instance defaults to App's view\n * @param {...args} Additional args that get passed along\n * @returns {View}\n */\n showView(view = this._view, ...args) {\n this.getRegion().show(view, ...args);\n\n return view;\n },\n\n /**\n * Shows a view in the region of the app's view\n *\n * @public\n * @method showChildView\n * @param {String} regionName - Name of region to show in\n * @param {View} view - Child view instance\n * @param {...args} Additional args that get passed along\n * @returns {View} - Child view instance\n */\n showChildView(regionName, view, ...args) {\n this.getView().showChildView(regionName, view, ...args);\n\n return view;\n },\n\n /**\n * Returns view from the App view by region name.\n *\n * @public\n * @method getChildView\n * @param {String} regionName - Name of region to get view from\n * @returns {View}\n */\n getChildView(regionName) {\n return this.getView().getChildView(regionName);\n }\n});\n\n_.extend(App.prototype, StateMixin, ChildAppsMixin, EventListenersMixin, ViewEventsMixin);\n\nexport default App;\n","import _ from 'underscore';\nimport Backbone from 'backbone';\nimport { Application, View } from 'backbone.marionette';\nimport StateMixin from './mixins/state';\nimport ViewEventsMixin from './mixins/view-events';\n\nconst ClassOptions = [\n 'regionOptions',\n 'ViewClass',\n 'viewEventPrefix',\n 'viewEvents',\n 'viewTriggers',\n 'viewOptions'\n];\n\n/**\n * Reusable Marionette.MnObject with View management boilerplate\n *\n * @public\n * @class Component\n * @memberOf Toolkit\n * @memberOf Marionette\n */\nconst Component = Application.extend({\n\n /**\n * The view class to be managed.\n * @type {Mn.View|Mn.CollectionView}\n * @default Marionette.View\n */\n ViewClass: View,\n\n /**\n * @public\n * @constructs Component\n * @param {Object} [options] - Settings for the component.\n * @param {Object} [options.state] - Attributes to set on the state model.\n * @param {Mn.View|Mn.CollectionView} [options.ViewClass]\n * - The view class to be managed.\n * @param {String} [options.viewEventPrefix]\n * - Used as the prefix for events forwarded from the component's view to the component\n * @param {Object} [options.viewOptions] - Options hash passed to an instantiated ViewClass.\n * @param {Marionette.Region} [options.region] - The region to show the component in.\n */\n constructor(options = {}) {\n // Make defaults available to this\n this.mergeOptions(options, ClassOptions);\n\n this.options = _.extend({}, _.result(this, 'options'), options);\n\n // ViewEventMixin\n this._buildEventProxies();\n\n // StateMixin\n this._initState(options);\n\n Application.call(this, options);\n\n // StateMixin\n this.delegateStateEvents();\n },\n\n /**\n * Set the Component's region and then show it.\n *\n * @public\n * @method showIn\n * @memberOf Component\n * @param {Marionette.Region} region - The region for the component\n * @param {Object} [viewOptions] - Options hash mixed into the instantiated ViewClass.\n * @returns {Component}\n */\n showIn(region, viewOptions) {\n this._region = region;\n\n this.show(viewOptions);\n\n return this;\n },\n\n /**\n * Show the Component in its region.\n *\n * @public\n * @event Component#before:show\n * @event Component#show\n * @throws ComponentRegionError - Thrown if component has no defined region.\n * @method show\n * @param {Object} [viewOptions] - Options hash mixed into the instantiated ViewClass.\n * @param {Object} [regionOptions] - Options hash passed to the region on show.\n * @memberOf Component\n * @returns {Component}\n */\n show(viewOptions, regionOptions) {\n const region = this.getRegion();\n\n if (!region) {\n throw new Error('Component has no defined region.');\n }\n\n const view = this._getView(viewOptions);\n\n this.stopListening(region.currentView, 'destroy', this.destroy);\n\n this.triggerMethod('before:show', this, view, viewOptions, regionOptions);\n\n this.showView(view, this.mixinRegionOptions(regionOptions));\n\n this.listenTo(region.currentView, 'destroy', this.destroy);\n\n this.triggerMethod('show', this, view, viewOptions, regionOptions);\n\n return this;\n },\n\n /**\n * Empty the Components region without destroying it\n *\n * @public\n * @throws ComponentRegionError - Thrown if component has no defined region.\n * @method empty\n * @memberOf Component\n * @returns {Component}\n */\n empty() {\n const region = this.getRegion();\n\n if (!region) {\n throw new Error('Component has no defined region.');\n }\n\n this.stopListening(region.currentView, 'destroy', this.destroy);\n\n region.empty();\n\n return this;\n },\n\n /**\n * Mixin regionOptions\n *\n * @public\n * @abstract\n * @method mixinRegionOptions\n * @memberOf Component\n * @param {Object} [options] - Additional options to mixin\n * @returns {Object}\n */\n mixinRegionOptions(options) {\n const regionOptions = _.result(this, 'regionOptions');\n\n return _.extend({}, regionOptions, options);\n },\n\n /**\n * Get the Component view instance.\n *\n * @private\n * @method _getView\n * @memberOf Component\n * @param {Object} [options] - Options that can be used to determine the ViewClass.\n * @returns {View}\n */\n _getView(options) {\n const ViewClass = this._getViewClass(options);\n\n const viewOptions = this.mixinViewOptions(options);\n\n const view = this.buildView(ViewClass, viewOptions);\n\n // ViewEventMixin\n this._proxyViewEvents(view);\n\n return view;\n },\n\n /**\n * Get the Component ViewClass class.\n * Checks if the `ViewClass` is a view class (the common case)\n * Then check if it's a function (which we assume that returns a view class)\n *\n * @private\n * @method _getViewClass\n * @memberOf Component\n * @param {Object} [options] - Options that can be used to determine the ViewClass.\n * @returns {View}\n */\n _getViewClass(options = {}) {\n const ViewClass = this.ViewClass;\n\n if (ViewClass.prototype instanceof Backbone.View || ViewClass === Backbone.View) {\n return ViewClass;\n } else if (_.isFunction(ViewClass)) {\n return ViewClass.call(this, options);\n }\n\n throw new Error('\"ViewClass\" must be a view class or a function that returns a view class');\n },\n\n /**\n * Mixin initial State with any other viewOptions\n *\n * @public\n * @abstract\n * @method mixinViewOptions\n * @memberOf Component\n * @param {Object} [options] - Additional options to mixin\n * @returns {Object}\n */\n mixinViewOptions(options) {\n const viewOptions = _.result(this, 'viewOptions');\n\n return _.extend({ state: this.getState().attributes }, viewOptions, options);\n },\n\n /**\n * Builds the view class with options\n * If you need a dynamic ViewClass override this function\n *\n * @public\n * @abstract\n * @method buildView\n * @memberOf Component\n * @param {Mn.View|Mn.CollectionView} ViewClass -\n * The view class to instantiate.\n * @param {Object} [viewOptions] - Options to pass to the View\n * @returns {Mn.View|Mn.CollectionView}\n */\n buildView(ViewClass, viewOptions) {\n return new ViewClass(viewOptions);\n },\n\n /**\n * Empty the region and destroy the component.\n *\n * @public\n * @method destroy\n * @param {Object} [options] - Options passed to Mn.Application `destroy`\n * @memberOf Component\n */\n destroy() {\n if (this._isDestroyed) {\n return this;\n }\n\n const region = this.getRegion();\n if (region) {region.empty();}\n\n Application.prototype.destroy.apply(this, arguments);\n\n return this;\n }\n}, {\n /**\n * Sets the region for a Component Class\n *\n * @public\n * @method setRegion\n * @param {Marionette.Region} - region definition for instantiated components\n * @memberOf Component.prototype\n */\n setRegion(region) {\n this.prototype.region = region;\n }\n});\n\n_.extend(Component.prototype, StateMixin, ViewEventsMixin);\n\nexport default Component;\n","import _ from 'underscore';\n\nimport StateMixin from './mixins/state';\nimport App from './app';\nimport Component from './component';\n\nimport { version as VERSION } from '../package.json';\n\n/**\n * @module Toolkit\n */\n\nfunction mixinState(classDefinition) {\n let _StateMixin = StateMixin;\n\n if (classDefinition.prototype.StateModel) {\n _StateMixin = _.omit(StateMixin, 'StateModel');\n }\n\n _.extend(classDefinition.prototype, _StateMixin);\n}\n\nexport {\n App,\n Component,\n mixinState,\n StateMixin,\n VERSION\n};\n"],"names":["ClassOptions","StateModel","Backbone","Model","initState","options","_initState","delegateStateEvents","mergeOptions","_removeEventHandlers","_getStateModel","_stateModel","state","_setEventHandlers","undelegateStateEvents","bindEvents","_","result","unbindEvents","on","_destroyState","stopListening","off","prototype","isFunction","call","Error","setState","set","apply","arguments","resetStateDefaults","defaults","getState","attr","get","toggleState","val","length","hasState","has","_initChildApps","_childApps","childApps","addChildApps","_getChildStartOpts","childApp","tkOpts","_tkOpts","opts","region","getRegion","regionName","each","getOptions","opt","getOption","_startChildApp","start","extend","_shouldActWithRestart","action","_isRestarting","restartWithParent","_startChildApps","_stopChildApps","stop","startChildApp","appName","getChildApp","stopChildApp","_destroyChildApps","destroy","_buildAppFromObject","appConfig","AppClass","omit","app","buildApp","pick","_buildApp","isObject","childAppOptions","_ensureAppIsUnique","bind","addChildApp","_name","_on","partial","_removeChildApp","isRunning","getName","getChildApps","clone","removeChildApps","removeChildApp","preventDestroy","_stopRunningEvents","_runningEvents","args","_stopRunningListeners","_runningListeningTo","_isRunning","push","MnObject","listenTo","_listenTo","listenToOnce","viewEventPrefix","_buildEventProxies","viewEvents","_viewEvents","normalizeMethods","_viewTriggers","_viewEventPrefix","_proxyViewEvents","view","_childViewEventHandler","eventName","viewTriggers","isString","triggerMethod","prefix","viewEventName","App","Application","startAfterInitialized","startWithParent","stopWithParent","constructor","_ensureAppIsIntact","_isDestroyed","isRestarting","setRegion","setView","_bindRunningEvents","triggerStart","_region","_regionEventMonitor","_view","restart","attributes","finallyStart","_removeView","currentView","_onBeforeShow","_onEmpty","getView","showView","show","showChildView","getChildView","StateMixin","ChildAppsMixin","EventListenersMixin","ViewEventsMixin","Component","ViewClass","View","showIn","viewOptions","regionOptions","_getView","mixinRegionOptions","empty","_getViewClass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ACD;;EAEDxI,EAAAA,CAAC,CAAC2C,MAAF,CAAS8G,eAAe,CAAClJ,SAAzB,EAAoCmJ,WAApC;EACD;;;;;;;;;;;;;;;;"} \ No newline at end of file +{"version":3,"file":"marionette.toolkit.js","sources":["../src/mixins/state.js","../src/mixins/child-apps.js","../src/mixins/event-listeners.js","../src/mixins/view-events.js","../src/app.js","../src/component.js","../src/marionette.toolkit.js"],"sourcesContent":["import _ from 'underscore';\nimport Backbone from 'backbone';\n\nconst ClassOptions = [\n 'StateModel',\n 'stateEvents'\n];\n\n/**\n * This provides methods used for keeping state using a Backbone.Model. It's meant to\n * be used with either a Marionette.MnObject or Backbone.View.\n *\n * @mixin\n */\nexport default {\n\n /**\n * The model class for _stateModel.\n * @type {Backbone.Model}\n * @default Backbone.Model\n */\n StateModel: Backbone.Model,\n\n /**\n * @public\n * @method initState\n * @param {Object} [options] - Settings for the StateMixin.\n * @param {Object} [options.stateEvents] - Event hash bound from _stateModel to StateMixin.\n * @param {Backbone.Model} [options.StateModel] - Model class for _stateModel.\n */\n initState(options = {}) {\n this._initState(options);\n this.delegateStateEvents();\n\n return this;\n },\n\n /**\n * @private\n * @method _initState\n * @param {Object} [options] - Settings for the StateMixin.\n */\n _initState(options) {\n // Make defaults available to this\n this.mergeOptions(options, ClassOptions);\n\n // Remove event handlers from previous state\n this._removeEventHandlers();\n\n const StateModel = this._getStateModel(options);\n\n this._stateModel = new StateModel(options.state);\n\n this._setEventHandlers();\n },\n\n /**\n * Bind events from the _stateModel defined in stateEvents hash\n *\n * @public\n * @method delegateStateEvents\n */\n delegateStateEvents() {\n this.undelegateStateEvents();\n this.bindEvents(this._stateModel, _.result(this, 'stateEvents'));\n\n return this;\n },\n\n /**\n * Unbind all entity events on _stateModel\n *\n * @public\n * @method undelegateStateEvents\n */\n undelegateStateEvents() {\n this.unbindEvents(this._stateModel);\n\n return this;\n },\n\n /**\n * Setup destroy event handle\n *\n * @private\n * @method _setEventHandlers\n */\n _setEventHandlers() {\n this.on('destroy', this._destroyState);\n },\n\n /**\n * Clean up destroy event handler, remove any listeners on _stateModel\n *\n * @private\n * @method _removeEventHandlers\n */\n _removeEventHandlers() {\n if (!this._stateModel) {return;}\n\n this.undelegateStateEvents();\n this._stateModel.stopListening();\n this.off('destroy', this._destroyState);\n },\n\n\n /**\n * Get the StateMixin StateModel class.\n * Checks if the `StateModel` is a model class (the common case)\n * Then check if it's a function (which we assume that returns a model class)\n *\n * @private\n * @method _getStateModel\n * @param {Object} [options] - Options that can be used to determine the StateModel.\n * @returns {Backbone.Model}\n */\n _getStateModel(options) {\n if (this.StateModel.prototype instanceof Backbone.Model || this.StateModel === Backbone.Model) {\n return this.StateModel;\n } else if (_.isFunction(this.StateModel)) {\n return this.StateModel.call(this, options);\n }\n\n throw new Error('\"StateModel\" must be a model class or a function that returns a model class');\n },\n\n /**\n * Set a property on the _stateModel.\n *\n * @public\n * @method setState\n * @param {String|Object} key - Attribute name or Hash of any number of key value pairs.\n * @param {*} [value] - Attribute value if key is String, replaces options param otherwise.\n * @param {Object} [options] - Backbone.Model options.\n * @returns {Backbone.Model} - The _stateModel\n */\n setState() {\n return this._stateModel.set.apply(this._stateModel, arguments);\n },\n\n\n /**\n * Reset _stateModel to defined defaults\n *\n * @public\n * @method resetStateDefaults\n * @param {Object} [newState] - Hash of any number of key value pairs.\n * @returns {Backbone.Model|*} - The _stateModel or the attribute value of the _stateModel\n */\n resetStateDefaults() {\n const defaults = _.result(this._stateModel, 'defaults');\n\n return this._stateModel.set(defaults);\n },\n\n /**\n * Get a property from the _stateModel, or return the _stateModel\n *\n * @public\n * @method getState\n * @param {String} [attr] - Attribute name of stateModel.\n * @returns {Backbone.Model|*} - The _stateModel or the attribute value of the _stateModel\n */\n getState(attr) {\n if (!attr) {\n return this._stateModel;\n }\n\n return this._stateModel.get.apply(this._stateModel, arguments);\n },\n\n /**\n * Toggle a property on the _stateModel.\n *\n * @public\n * @method toggleState\n * @param {String} attr - Attribute name of stateModel.\n * @param {val} [value] - Attribute value.\n * @returns {Backbone.Model} - The _stateModel or attribute value.\n */\n toggleState(attr, val) {\n if (arguments.length > 1) {return this._stateModel.set(attr, !!val);}\n\n return this._stateModel.set(attr, !this._stateModel.get(attr));\n },\n\n /**\n * Check if _stateModel has a property\n *\n * @public\n * @method hasState\n * @param {String} [attr] - Attribute name of stateModel.\n * @returns {Boolean}\n */\n hasState(attr) {\n return this._stateModel.has(attr);\n },\n\n /**\n * Clean up any listeners on the _stateModel.\n *\n * @private\n * @method _destroyState\n */\n _destroyState() {\n this._stateModel.stopListening();\n }\n};\n","import _ from 'underscore';\n\nconst ClassOptions = [\n 'childApps',\n 'childAppOptions'\n];\n\n/**\n * This provides methods used for \"App Manager\" functionality - the adding and removing child `App`s. It's not meant to\n * be used directly.\n *\n * @mixin\n */\nexport default {\n\n /**\n * @private\n * @method _initChildApps\n * @constructs ChildApps\n * @param {Object} [options] - Settings for the ChildApps.\n * @param {Object} [options.childApps] - Hash for setting up child apps.\n * @param {Object} [options.childAppOptions] - Hash of options passed to every child app.\n *\n * ```js\n * childApps: {\n * appName: {\n * AppClass: MyChildAppClass,\n * fooOption: true,\n * startWithParent: true\n * },\n * barApp: MyOtherChildAppClass\n * }\n * ```\n */\n _initChildApps(options = {}) {\n this._childApps = {};\n\n this.mergeOptions(options, ClassOptions);\n\n let childApps = this.childApps;\n\n if (childApps) {\n if (_.isFunction(childApps)) {\n childApps = childApps.call(this, options);\n }\n\n this.addChildApps(childApps);\n }\n },\n\n /**\n * Finds `regionName` and `getOptions` for the childApp\n *\n * @private\n * @method _getChildStartOpts\n */\n _getChildStartOpts(childApp) {\n const tkOpts = childApp._tkOpts || {};\n\n const opts = {\n region: this.getRegion(tkOpts.regionName)\n };\n\n _.each(tkOpts.getOptions, opt => {\n opts[opt] = this.getOption(opt);\n });\n\n return opts;\n },\n\n /**\n * Starts a `childApp`\n *\n * @private\n * @method _startChildApp\n */\n _startChildApp(childApp, options) {\n const opts = this._getChildStartOpts(childApp);\n return childApp.start(_.extend(opts, options));\n },\n\n /**\n * Handles explicit boolean values of restartWithParent\n * restartWithParent === false does nothing\n *\n * @private\n * @method _shouldStartWithRestart\n */\n _shouldActWithRestart(childApp, action) {\n if (!this._isRestarting) {return true;}\n const restartWithParent = _.result(childApp, 'restartWithParent');\n if (restartWithParent === true) {return true;}\n if (restartWithParent !== false && _.result(childApp, action)) {return true;}\n },\n\n /**\n * Starts `childApps` if allowed by child\n *\n * @private\n * @method _startChildApps\n */\n _startChildApps() {\n const action = 'startWithParent';\n _.each(this._childApps, childApp => {\n if (!this._shouldActWithRestart(childApp, action)) {return;}\n if (!this._isRestarting && !_.result(childApp, action)) {return;}\n this._startChildApp(childApp);\n });\n },\n\n /**\n * Stops `childApps` if allowed by child\n *\n * @private\n * @method _stopChildApps\n */\n _stopChildApps() {\n const action = 'stopWithParent';\n _.each(this._childApps, childApp => {\n if (!this._shouldActWithRestart(childApp, action)) {return;}\n if (!this._isRestarting && !_.result(childApp, action)) {return;}\n childApp.stop();\n });\n },\n\n /**\n * Starts `childApp`\n *\n * @param {String} appName - Name of childApp to start\n * @param {Object} options - Start options for app\n * @public\n * @method startChildApp\n */\n startChildApp(appName, options) {\n const childApp = this.getChildApp(appName);\n return this._startChildApp(childApp, options);\n },\n\n /**\n * Stops `childApp`\n *\n * @param {String} appName - Name of childApp to stop\n * @param {Object} options - Stop options for app\n * @public\n * @method stopChildApp\n */\n stopChildApp(appName, options) {\n return this.getChildApp(appName).stop(options);\n },\n\n /**\n * Destroys `childApps` if allowed by child\n *\n * @private\n * @method _destroyChildApps\n */\n _destroyChildApps() {\n _.each(this._childApps, function(childApp) {\n if (!_.result(childApp, 'preventDestroy')) {\n childApp.destroy();\n }\n });\n },\n\n /**\n * Internal helper to instantiate and `App` from on `Object`\n *\n * @private\n * @method _buildAppFromObject\n * @param {Object} appConfig - `AppClass` and any other option for the `App`\n * @returns {App}\n */\n _buildAppFromObject(appConfig) {\n const AppClass = appConfig.AppClass;\n const options = _.omit(appConfig, 'AppClass', 'regionName', 'getOptions');\n\n const app = this.buildApp(AppClass, options);\n\n app._tkOpts = _.pick(appConfig, 'regionName', 'getOptions');\n\n return app;\n },\n\n /**\n * Helper for building an App and return it\n *\n * @private\n * @method _buildApp\n * @param {App} AppClass - An App Class\n * @param {Object} AppClass - Optionally passed as an appConfig Object\n * @param {Object} [options] - options for the AppClass\n * @returns {App}\n */\n _buildApp(AppClass, options) {\n if (_.isFunction(AppClass)) {\n return this.buildApp(AppClass, options);\n }\n if (_.isObject(AppClass)) {\n return this._buildAppFromObject(AppClass);\n }\n },\n\n /**\n * Build an App and return it\n * Override for dynamic App building\n *\n * @public\n * @method buildApp\n * @param {App} [AppClass] - An App Class\n * @param {Object} [options] - options for the AppClass\n * @returns {App}\n */\n buildApp(AppClass, options) {\n // options on childApp definition supersede childAppOptions\n options = _.extend({}, this.childAppOptions, options);\n\n return new AppClass(options);\n },\n\n /**\n * Internal helper to verify `appName` is unique and not in use\n *\n * @private\n * @method _ensureAppIsUnique\n * @param {String} appName - Name of app to test\n * @throws DuplicateChildAppError - Thrown if `App` already has an `appName` registered\n */\n _ensureAppIsUnique(appName) {\n if (this._childApps[appName]) {\n throw new Error(`A child App with name \"${ appName }\" has already been added.`);\n }\n },\n\n /**\n * Add child `App`s to this `App`\n *\n * @public\n * @method addChildApps\n * @param {Object} childApps - Hash of names and `AppClass` or `appConfig`\n */\n addChildApps(childApps) {\n _.each(childApps, _.bind(function(childApp, appName) {\n this.addChildApp(appName, childApp);\n }, this));\n },\n\n /**\n * Build's childApp and registers it with this App\n * Starts the childApp, if this app is running and child is `startWithParent`\n *\n * @public\n * @method addChildApp\n * @param {String} appName - Name of App to register\n * @param {App} AppClass - An App Class\n * @param {Object} AppClass - Optionally passed as an appConfig Object\n * @param {Object} [options] - options for the AppClass\n * @throws AddChildAppError - Thrown if no childApp could be built from params\n * @returns {App}\n */\n addChildApp(appName, AppClass, options) {\n this._ensureAppIsUnique(appName);\n\n const childApp = this._buildApp(AppClass, options);\n\n if (!childApp) {\n throw new Error('App build failed. Incorrect configuration.');\n }\n\n childApp._name = appName;\n\n this._childApps[appName] = childApp;\n\n // When the app is destroyed remove the cached app.\n // Listener setup relative to the childApp's running state (using _on)\n childApp._on('destroy', _.partial(this._removeChildApp, appName), this);\n\n if (this.isRunning() && _.result(childApp, 'startWithParent')) {\n this._startChildApp(childApp);\n }\n\n return childApp;\n },\n\n /**\n * Returns registered child `App`s name\n *\n * @public\n * @method getName\n * @returns {String}\n */\n getName() {\n return this._name;\n },\n\n\n /**\n * Returns registered child `App`s array\n *\n * @public\n * @method getChildApps\n * @returns {Array}\n */\n getChildApps() {\n return _.clone(this._childApps);\n },\n\n /**\n * Returns registered child `App`\n *\n * @public\n * @method getChildApp\n * @param {String} appName - Name of App to retrieve\n * @returns {App}\n */\n getChildApp(appName) {\n return this._childApps[appName];\n },\n\n /**\n * Internal helper. Unregisters child `App`\n *\n * @private\n * @method _removeChildApp\n * @param {String} appName - Name of App to unregister\n * @returns {App}\n */\n _removeChildApp(appName) {\n delete this._childApps[appName]._name;\n delete this._childApps[appName];\n },\n\n /**\n * Removes all childApps and returns them.\n * The return is useful if any app is using `preventDestroy`\n *\n * @public\n * @method removeChildApps\n * @returns {Array}\n */\n removeChildApps() {\n const childApps = this.getChildApps();\n\n _.each(this._childApps, _.bind(function(childApp, appName) {\n this.removeChildApp(appName);\n }, this));\n\n return childApps;\n },\n\n /**\n * Destroys or removes registered child `App` by name\n * depending on `preventDestroy`\n *\n * @public\n * @method removeChildApp\n * @param {String} appName - Name of App to destroy\n * @param {Object} [options.preventDestroy] - Flag to remove but prevent App destroy\n * @returns {App}\n */\n removeChildApp(appName, options) {\n options = _.extend({}, options);\n\n const childApp = this.getChildApp(appName);\n\n if (!childApp) {\n return;\n }\n\n // if preventDestroy simply unregister the child app\n if (options.preventDestroy || _.result(childApp, 'preventDestroy')) {\n this._removeChildApp(appName);\n } else {\n childApp.destroy();\n }\n\n return childApp;\n }\n};\n","import _ from 'underscore';\nimport { MnObject } from 'backbone.marionette';\n\n/**\n * This provides methods used for registering events while App is running and cleans them up at `onStop`. It's not meant to\n * be used directly.\n *\n * @mixin\n */\n\nexport default {\n /**\n * Internal method to stop any registered events.\n *\n * @private\n * @method _stopRunningEvents\n */\n _stopRunningEvents() {\n _.each(this._runningEvents, _.bind(function(args) {\n this.off.apply(this, args);\n }, this));\n this._runningEvents = [];\n },\n\n /**\n * Internal method to stop any registered listeners.\n *\n * @private\n * @method _stopRunningListeners\n */\n _stopRunningListeners() {\n _.each(this._runningListeningTo, _.bind(function(args) {\n this.stopListening.apply(this, args);\n }, this));\n this._runningListeningTo = [];\n },\n\n /**\n * Overrides `Backbone.Event.on()`\n * If this `App` is running it will register the event for removal `onStop`\n *\n * @public\n * @method on\n * @returns {EventListeners}\n */\n on() {\n if (this._isRunning) {\n this._runningEvents = (this._runningEvents || []);\n this._runningEvents.push(arguments);\n }\n\n return MnObject.prototype.on.apply(this, arguments);\n },\n\n /**\n * Keep a copy of non-running on for internal use\n *\n * @private\n * @method _on\n * @returns {EventListeners}\n */\n _on: MnObject.prototype.on,\n\n /**\n * Overrides `Backbone.Event.listenTo()`\n * If this `App` is running it will register the listener for removal `onStop`\n *\n * @public\n * @method listenTo\n * @returns {EventListeners}\n */\n listenTo() {\n if (this._isRunning) {\n this._runningListeningTo = (this._runningListeningTo || []);\n this._runningListeningTo.push(arguments);\n }\n return MnObject.prototype.listenTo.apply(this, arguments);\n },\n\n /**\n * Keep a copy of non-running on for internal use\n *\n * @private\n * @method _listenTo\n * @returns {EventListeners}\n */\n _listenTo: MnObject.prototype.listenTo,\n\n /**\n * Overrides `Backbone.Event.listenToOnce()`\n * If this `App` is running it will register the listener for removal `onStop`\n *\n * @public\n * @method listenToOnce\n * @returns {EventListeners}\n */\n listenToOnce() {\n if (this._isRunning) {\n this._runningListeningTo = (this._runningListeningTo || []);\n this._runningListeningTo.push(arguments);\n }\n\n return MnObject.prototype.listenToOnce.apply(this, arguments);\n }\n};\n","import _ from 'underscore';\n\nexport default {\n /**\n * Used as the prefix for events forwarded from\n * the component's view to the component\n * @type {String}\n * @default false\n */\n viewEventPrefix: false,\n\n /**\n * Constructs hashes and options for view event proxy\n *\n * @private\n * @method _buildEventProxies\n */\n _buildEventProxies() {\n const viewEvents = _.result(this, 'viewEvents') || {};\n this._viewEvents = this.normalizeMethods(viewEvents);\n this._viewTriggers = _.result(this, 'viewTriggers') || {};\n this._viewEventPrefix = _.result(this, 'viewEventPrefix');\n },\n\n /**\n * Proxies the ViewClass's viewEvents to the Component itself\n * Similar to CollectionView childEvents\n * (http://marionettejs.com/docs/v2.3.2/marionette.collectionview.html#collectionviews-childevents)\n *\n * @private\n * @method _proxyViewEvents\n * @param {Mn.View|Mn.CollectionView} view -\n * The instantiated ViewClass.\n */\n _proxyViewEvents(view) {\n this.listenTo(view, 'all', this._childViewEventHandler);\n },\n\n /**\n * Event handler for view proxy\n * Similar to CollectionView childEvents\n * (http://marionettejs.com/docs/v2.3.2/marionette.collectionview.html#collectionviews-childevents)\n *\n * @private\n * @method _childViewEventHandler\n * @param {String} - event name\n */\n _childViewEventHandler(eventName, ...args) {\n const viewEvents = this._viewEvents;\n\n if (_.isFunction(viewEvents[eventName])) {\n viewEvents[eventName].apply(this, args);\n }\n\n // use the parent view's proxyEvent handlers\n const viewTriggers = this._viewTriggers;\n\n // Call the event with the proxy name on the parent layout\n if (_.isString(viewTriggers[eventName])) {\n this.triggerMethod(viewTriggers[eventName], ...args);\n }\n\n const prefix = this._viewEventPrefix;\n\n if (prefix !== false) {\n const viewEventName = `${ prefix }:${ eventName }`;\n\n this.triggerMethod(viewEventName, ...args);\n }\n }\n};\n","import _ from 'underscore';\nimport { Application } from 'backbone.marionette';\nimport StateMixin from './mixins/state';\nimport ChildAppsMixin from './mixins/child-apps';\nimport EventListenersMixin from './mixins/event-listeners';\nimport ViewEventsMixin from './mixins/view-events';\n\nconst ClassOptions = [\n 'startWithParent',\n 'restartWithParent',\n 'stopWithParent',\n 'startAfterInitialized',\n 'preventDestroy',\n 'StateModel',\n 'stateEvents',\n 'viewEventPrefix',\n 'viewEvents',\n 'viewTriggers'\n];\n\n/**\n * Marionette.Application with an `initialize` / `start` / `stop` / `destroy` lifecycle.\n *\n * @public\n * @class App\n * @memberOf Toolkit\n * @memberOf Marionette\n */\nconst App = Application.extend({\n\n /**\n * Internal flag indiciate when `App` has started but has not yet stopped.\n *\n * @private\n * @type {Boolean}\n * @default false\n */\n _isRunning: false,\n\n /**\n * Internal flag indiciate when `App` is in the process of stopping then starting.\n *\n * @private\n * @type {Boolean}\n * @default false\n */\n _isRestarting: false,\n\n /**\n * Set to true if a parent `App` should not be able to destroy this `App`.\n *\n * @type {Boolean|Function}\n * @default false\n */\n preventDestroy: false,\n\n /**\n * Set to true if `App` should be started after it is initialized.\n *\n * @type {Boolean|Function}\n * @default false\n */\n startAfterInitialized: false,\n\n /**\n * Set to true if `App` should be started after its parent starts.\n *\n * @type {Boolean|Function}\n * @default false\n */\n startWithParent: false,\n\n /**\n * Set to false if `App` should not stop after its parent stops.\n *\n * @type {Boolean|Function}\n * @default true\n */\n stopWithParent: true,\n\n\n /**\n * Set this to determine if a parent `App` should maintain the child's\n * lifecycle during a restart.\n *\n * @type {Boolean|Function}\n * @default null\n */\n restartWithParent: null,\n\n /**\n * @public\n * @constructs App\n * @param {Object} [options] - Settings for the App.\n * @param {Boolean} [options.startWithParent]\n * @param {Boolean} [options.restartWithParent]\n * @param {Boolean} [options.stopWithParent]\n * @param {Boolean} [options.startAfterInitialized]\n * @param {Boolean} [options.preventDestroy]\n * @param {Object} [options.state] - Attributes to set on the state model.\n */\n constructor(options = {}) {\n this.mergeOptions(options, ClassOptions);\n\n this.options = _.extend({}, _.result(this, 'options'), options);\n\n // ChildAppsMixin\n this._initChildApps(options);\n\n Application.call(this, options);\n\n if (_.result(this, 'startAfterInitialized')) {\n this.start(options);\n }\n },\n\n /**\n * Internal helper to verify if `App` has been destroyed\n *\n * @private\n * @method _ensureAppIsIntact\n * @memberOf App\n * @throws AppDestroyedError - Thrown if `App` has already been destroyed\n */\n _ensureAppIsIntact() {\n if (this._isDestroyed) {\n throw new Error('App has already been destroyed and cannot be used.');\n }\n },\n\n /**\n * Gets the value of internal `_isRunning` flag\n *\n * @public\n * @method isRunning\n * @memberOf App\n * @returns {Boolean}\n */\n isRunning() {\n return this._isRunning;\n },\n\n /**\n * Gets the value of internal `_isRestarting` flag\n *\n * @public\n * @method isRestarting\n * @memberOf App\n * @returns {Boolean}\n */\n isRestarting() {\n return this._isRestarting;\n },\n\n /**\n * Sets the app lifecycle to running.\n *\n * @public\n * @method start\n * @memberOf App\n * @param {Object} [options] - Settings for the App passed through to events\n * @event App#before:start - passes options\n * @returns {App}\n */\n start(options = {}) {\n this._ensureAppIsIntact();\n\n if (this._isRunning) {\n return this;\n }\n\n if (options.region) {\n this.setRegion(options.region);\n }\n\n if (options.view) {\n this.setView(options.view);\n }\n\n // StateMixin\n this._initState(options);\n\n // ViewEventMixin\n this._buildEventProxies();\n\n this.triggerMethod('before:start', options);\n\n this._isRunning = true;\n\n this._bindRunningEvents();\n\n this.triggerStart(options);\n\n return this;\n },\n\n /**\n * Sets up region, view, and state events.\n * To only be called after `isRunning` is true\n *\n * @private\n * @method _bindRunningEvents\n * @memberOf App\n */\n _bindRunningEvents() {\n if (this._region) {\n this._regionEventMonitor();\n }\n\n if (this._view) {\n this._proxyViewEvents(this._view);\n }\n\n // StateMixin\n this.delegateStateEvents();\n },\n\n /**\n * Sets the app lifecycle to not running\n * then sets the app lifecycle to running with ending state\n *\n * @public\n * @method restart\n * @memberOf App\n * @returns {App}\n */\n restart() {\n const state = this.getState().attributes;\n\n this._isRestarting = true;\n this.stop().start({ state });\n this._isRestarting = false;\n\n return this;\n },\n\n /**\n * Starts children and triggers start event\n * For calling within `triggerStart`\n *\n * @public\n * @method finallyStart\n * @memberOf App\n * @event App#start - passes any arguments\n * @returns\n */\n finallyStart() {\n this._startChildApps();\n this.triggerMethod('start', ...arguments);\n },\n\n /**\n * Triggers start event via finallyStart.\n * Override to introduce async start\n *\n * @public\n * @method triggerStart\n * @memberOf App\n * @param {Object} [options] - Settings for the App passed through to events\n * @returns\n */\n triggerStart(options) {\n this.finallyStart(options);\n },\n\n /**\n * Sets the app lifecycle to not running.\n * Removes any listeners added during the running state\n *\n * @public\n * @method stop\n * @memberOf App\n * @param {Object} [options] - Settings for the App passed through to events\n * @event App#before:stop - passes options\n * @event App#stop - passes options\n * @returns {App}\n */\n stop(options) {\n if (!this._isRunning) {\n return this;\n }\n\n this.triggerMethod('before:stop', options);\n\n this._stopChildApps();\n\n this._isRunning = false;\n\n this.triggerMethod('stop', options);\n\n // Running events are cleaned up after stop so that\n // `stop` event handlers still fire\n this._stopRunningListeners();\n this._stopRunningEvents();\n\n return this;\n },\n\n /**\n * Stops the `App` and sets it destroyed.\n *\n * @public\n * @method destroy\n * @memberOf App\n */\n destroy() {\n if (this._isDestroyed) {\n return this;\n }\n\n this.stop();\n\n this._removeView();\n\n this._destroyChildApps();\n\n Application.prototype.destroy.apply(this, arguments);\n\n return this;\n },\n\n /**\n * Set the Application's Region\n *\n * @public\n * @method setRegion\n * @memberOf App\n * @param {Region} [region] - Region to use with the app\n * @returns {Region}\n */\n setRegion(region) {\n if (this._region) {\n this.stopListening(this._region);\n }\n\n this._region = region;\n\n if (region.currentView) {\n this.setView(region.currentView);\n }\n\n if (this._isRunning) {\n this._regionEventMonitor();\n }\n\n return region;\n },\n\n /**\n * Monitors the apps region before:show event so the region's view\n * is available to the app\n *\n * @private\n * @method _regionEventMonitor\n * @memberOf App\n */\n _regionEventMonitor() {\n this.listenTo(this._region, {\n 'before:show': this._onBeforeShow,\n 'empty': this._onEmpty\n });\n },\n\n /**\n * Region monitor handler which sets the app's view to the region's view\n *\n * @private\n * @method _onBeforeShow\n * @memberOf App\n */\n _onBeforeShow(region, view) {\n this.setView(view);\n },\n\n /**\n * Region monitor handler which empties the region's view\n *\n * @private\n * @method _onEmpty\n * @memberOf App\n */\n _onEmpty(region, view) {\n if (view !== this._view) {return;}\n\n this._removeView();\n },\n\n /**\n * Region monitor handler which deletes the region's view and listeners to view\n *\n * @private\n * @method _removeView\n * @memberOf App\n */\n _removeView() {\n if (this._view) {\n this.stopListening(this._view);\n delete this._view;\n }\n },\n\n /**\n * Get the Application's Region or\n * Get a region from the Application's View\n *\n * @public\n * @method getRegion\n * @memberOf App\n * @param {String} [regionName] - Optional regionName to get from the view\n * @returns {Region}\n */\n getRegion(regionName) {\n if (!regionName) {\n return this._region;\n }\n\n return this.getView().getRegion(regionName);\n },\n\n /**\n * Set the Application's View\n *\n * @public\n * @method setView\n * @memberOf App\n * @param {View} [view] - View to use with the app\n * @returns {View}\n */\n setView(view) {\n if (this._view === view) {\n return view;\n }\n\n if (this._view) {\n this.stopListening(this._view);\n }\n\n this._view = view;\n\n // ViewEventsMixin\n if (this._isRunning) {\n this._proxyViewEvents(view);\n }\n\n // Internal non-running listener\n this._listenTo(this._view, 'destroy', this._removeView);\n\n return view;\n },\n\n /**\n * Get the Application's View\n *\n * @public\n * @method getView\n * @memberOf App\n * @returns {View}\n */\n getView() {\n return this._view || this._region && this._region.currentView;\n },\n\n /**\n * Shows a view in the Application's region\n *\n * @public\n * @method showView\n * @param {View} view - Child view instance defaults to App's view\n * @param {...args} Additional args that get passed along\n * @returns {View}\n */\n showView(view = this._view, ...args) {\n const region = this.getRegion();\n\n region.show(view, ...args);\n\n if (!this.isRunning()) {this.setView(region.currentView);}\n\n return view;\n },\n\n /**\n * Shows a view in the region of the app's view\n *\n * @public\n * @method showChildView\n * @param {String} regionName - Name of region to show in\n * @param {View} view - Child view instance\n * @param {...args} Additional args that get passed along\n * @returns {View} - Child view instance\n */\n showChildView(regionName, view, ...args) {\n this.getView().showChildView(regionName, view, ...args);\n\n return view;\n },\n\n /**\n * Returns view from the App view by region name.\n *\n * @public\n * @method getChildView\n * @param {String} regionName - Name of region to get view from\n * @returns {View}\n */\n getChildView(regionName) {\n return this.getView().getChildView(regionName);\n }\n});\n\n_.extend(App.prototype, StateMixin, ChildAppsMixin, EventListenersMixin, ViewEventsMixin);\n\nexport default App;\n","import _ from 'underscore';\nimport Backbone from 'backbone';\nimport { Application, View } from 'backbone.marionette';\nimport StateMixin from './mixins/state';\nimport ViewEventsMixin from './mixins/view-events';\n\nconst ClassOptions = [\n 'regionOptions',\n 'ViewClass',\n 'viewEventPrefix',\n 'viewEvents',\n 'viewTriggers',\n 'viewOptions'\n];\n\n/**\n * Reusable Marionette.MnObject with View management boilerplate\n *\n * @public\n * @class Component\n * @memberOf Toolkit\n * @memberOf Marionette\n */\nconst Component = Application.extend({\n\n /**\n * The view class to be managed.\n * @type {Mn.View|Mn.CollectionView}\n * @default Marionette.View\n */\n ViewClass: View,\n\n /**\n * @public\n * @constructs Component\n * @param {Object} [options] - Settings for the component.\n * @param {Object} [options.state] - Attributes to set on the state model.\n * @param {Mn.View|Mn.CollectionView} [options.ViewClass]\n * - The view class to be managed.\n * @param {String} [options.viewEventPrefix]\n * - Used as the prefix for events forwarded from the component's view to the component\n * @param {Object} [options.viewOptions] - Options hash passed to an instantiated ViewClass.\n * @param {Marionette.Region} [options.region] - The region to show the component in.\n */\n constructor(options = {}) {\n // Make defaults available to this\n this.mergeOptions(options, ClassOptions);\n\n this.options = _.extend({}, _.result(this, 'options'), options);\n\n // ViewEventMixin\n this._buildEventProxies();\n\n // StateMixin\n this._initState(options);\n\n Application.call(this, options);\n\n // StateMixin\n this.delegateStateEvents();\n },\n\n /**\n * Set the Component's region and then show it.\n *\n * @public\n * @method showIn\n * @memberOf Component\n * @param {Marionette.Region} region - The region for the component\n * @param {Object} [viewOptions] - Options hash mixed into the instantiated ViewClass.\n * @param {Object} [regionOptions] - Options hash mixed into the instantiated region.\n * @returns {Component}\n */\n showIn(region, viewOptions, regionOptions) {\n this._region = region;\n\n this.show(viewOptions, regionOptions);\n\n return this;\n },\n\n /**\n * Show the Component in its region.\n *\n * @public\n * @event Component#before:show\n * @event Component#show\n * @throws ComponentRegionError - Thrown if component has no defined region.\n * @method show\n * @param {Object} [viewOptions] - Options hash mixed into the instantiated ViewClass.\n * @param {Object} [regionOptions] - Options hash passed to the region on show.\n * @memberOf Component\n * @returns {Component}\n */\n show(viewOptions, regionOptions) {\n const region = this.getRegion();\n\n if (!region) {\n throw new Error('Component has no defined region.');\n }\n\n const view = this._getView(viewOptions);\n\n this.stopListening(region.currentView, 'destroy', this.destroy);\n\n this.triggerMethod('before:show', this, view, viewOptions, regionOptions);\n\n this.showView(view, this.mixinRegionOptions(regionOptions));\n\n this.listenTo(region.currentView, 'destroy', this.destroy);\n\n this.triggerMethod('show', this, view, viewOptions, regionOptions);\n\n return this;\n },\n\n /**\n * Empty the Components region without destroying it\n *\n * @public\n * @throws ComponentRegionError - Thrown if component has no defined region.\n * @method empty\n * @memberOf Component\n * @returns {Component}\n */\n empty() {\n const region = this.getRegion();\n\n if (!region) {\n throw new Error('Component has no defined region.');\n }\n\n this.stopListening(region.currentView, 'destroy', this.destroy);\n\n region.empty();\n\n return this;\n },\n\n /**\n * Mixin regionOptions\n *\n * @public\n * @abstract\n * @method mixinRegionOptions\n * @memberOf Component\n * @param {Object} [options] - Additional options to mixin\n * @returns {Object}\n */\n mixinRegionOptions(options) {\n const regionOptions = _.result(this, 'regionOptions');\n\n return _.extend({}, regionOptions, options);\n },\n\n /**\n * Get the Component view instance.\n *\n * @private\n * @method _getView\n * @memberOf Component\n * @param {Object} [options] - Options that can be used to determine the ViewClass.\n * @returns {View}\n */\n _getView(options) {\n const ViewClass = this._getViewClass(options);\n\n const viewOptions = this.mixinViewOptions(options);\n\n const view = this.buildView(ViewClass, viewOptions);\n\n // ViewEventMixin\n this._proxyViewEvents(view);\n\n return view;\n },\n\n /**\n * Get the Component ViewClass class.\n * Checks if the `ViewClass` is a view class (the common case)\n * Then check if it's a function (which we assume that returns a view class)\n *\n * @private\n * @method _getViewClass\n * @memberOf Component\n * @param {Object} [options] - Options that can be used to determine the ViewClass.\n * @returns {View}\n */\n _getViewClass(options = {}) {\n const ViewClass = this.ViewClass;\n\n if (ViewClass.prototype instanceof Backbone.View || ViewClass === Backbone.View) {\n return ViewClass;\n } else if (_.isFunction(ViewClass)) {\n return ViewClass.call(this, options);\n }\n\n throw new Error('\"ViewClass\" must be a view class or a function that returns a view class');\n },\n\n /**\n * Mixin initial State with any other viewOptions\n *\n * @public\n * @abstract\n * @method mixinViewOptions\n * @memberOf Component\n * @param {Object} [options] - Additional options to mixin\n * @returns {Object}\n */\n mixinViewOptions(options) {\n const viewOptions = _.result(this, 'viewOptions');\n\n return _.extend({ state: this.getState().attributes }, viewOptions, options);\n },\n\n /**\n * Builds the view class with options\n * If you need a dynamic ViewClass override this function\n *\n * @public\n * @abstract\n * @method buildView\n * @memberOf Component\n * @param {Mn.View|Mn.CollectionView} ViewClass -\n * The view class to instantiate.\n * @param {Object} [viewOptions] - Options to pass to the View\n * @returns {Mn.View|Mn.CollectionView}\n */\n buildView(ViewClass, viewOptions) {\n return new ViewClass(viewOptions);\n },\n\n /**\n * Empty the region and destroy the component.\n *\n * @public\n * @method destroy\n * @param {Object} [options] - Options passed to Mn.Application `destroy`\n * @memberOf Component\n */\n destroy() {\n if (this._isDestroyed) {\n return this;\n }\n\n const region = this.getRegion();\n if (region) {region.empty();}\n\n Application.prototype.destroy.apply(this, arguments);\n\n return this;\n }\n}, {\n /**\n * Sets the region for a Component Class\n *\n * @public\n * @method setRegion\n * @param {Marionette.Region} - region definition for instantiated components\n * @memberOf Component.prototype\n */\n setRegion(region) {\n this.prototype.region = region;\n }\n});\n\n_.extend(Component.prototype, StateMixin, ViewEventsMixin);\n\nexport default Component;\n","import _ from 'underscore';\n\nimport StateMixin from './mixins/state';\nimport App from './app';\nimport Component from './component';\n\nimport { version as VERSION } from '../package.json';\n\n/**\n * @module Toolkit\n */\n\nfunction mixinState(classDefinition) {\n let _StateMixin = StateMixin;\n\n if (classDefinition.prototype.StateModel) {\n _StateMixin = _.omit(StateMixin, 'StateModel');\n }\n\n _.extend(classDefinition.prototype, _StateMixin);\n}\n\nexport {\n App,\n Component,\n mixinState,\n StateMixin,\n VERSION\n};\n"],"names":["ClassOptions","StateModel","Backbone","Model","initState","options","_initState","delegateStateEvents","mergeOptions","_removeEventHandlers","_getStateModel","_stateModel","state","_setEventHandlers","undelegateStateEvents","bindEvents","_","result","unbindEvents","on","_destroyState","stopListening","off","prototype","isFunction","call","Error","setState","set","apply","arguments","resetStateDefaults","defaults","getState","attr","get","toggleState","val","length","hasState","has","_initChildApps","_childApps","childApps","addChildApps","_getChildStartOpts","childApp","tkOpts","_tkOpts","opts","region","getRegion","regionName","each","getOptions","opt","getOption","_startChildApp","start","extend","_shouldActWithRestart","action","_isRestarting","restartWithParent","_startChildApps","_stopChildApps","stop","startChildApp","appName","getChildApp","stopChildApp","_destroyChildApps","destroy","_buildAppFromObject","appConfig","AppClass","omit","app","buildApp","pick","_buildApp","isObject","childAppOptions","_ensureAppIsUnique","bind","addChildApp","_name","_on","partial","_removeChildApp","isRunning","getName","getChildApps","clone","removeChildApps","removeChildApp","preventDestroy","_stopRunningEvents","_runningEvents","args","_stopRunningListeners","_runningListeningTo","_isRunning","push","MnObject","listenTo","_listenTo","listenToOnce","viewEventPrefix","_buildEventProxies","viewEvents","_viewEvents","normalizeMethods","_viewTriggers","_viewEventPrefix","_proxyViewEvents","view","_childViewEventHandler","eventName","viewTriggers","isString","triggerMethod","prefix","viewEventName","App","Application","startAfterInitialized","startWithParent","stopWithParent","constructor","_ensureAppIsIntact","_isDestroyed","isRestarting","setRegion","setView","_bindRunningEvents","triggerStart","_region","_regionEventMonitor","_view","restart","attributes","finallyStart","_removeView","currentView","_onBeforeShow","_onEmpty","getView","showView","show","showChildView","getChildView","StateMixin","ChildAppsMixin","EventListenersMixin","ViewEventsMixin","Component","ViewClass","View","showIn","viewOptions","regionOptions","_getView","mixinRegionOptions","empty","_getViewClass","mixinViewOptions","buildView","mixinState","classDefinition","_StateMixin"],"mappings":";;;;;;;;;;;;;;;;;;;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eAApB,EAAqC;EACnC,MAAIC,WAAW,GAAGlB,UAAlB;;EAEA,MAAIiB,eAAe,CAAClJ,SAAhB,CAA0BtB,UAA9B,EAA0C;EACxCyK,IAAAA,WAAW,GAAG1J,CAAC,CAAC4D,IAAF,CAAO4E,UAAP,EAAmB,YAAnB,CAAd;EACD;;EAEDxI,EAAAA,CAAC,CAAC2C,MAAF,CAAS8G,eAAe,CAAClJ,SAAzB,EAAoCmJ,WAApC;EACD;;;;;;;;;;;;;;;;"} \ No newline at end of file diff --git a/dist/marionette.toolkit.min.js b/dist/marionette.toolkit.min.js index 2757a6c..407c6b8 100644 --- a/dist/marionette.toolkit.min.js +++ b/dist/marionette.toolkit.min.js @@ -1,8 +1,8 @@ /** * marionette.toolkit - A collection of opinionated Backbone.Marionette extensions for large scale application architecture. - * @version v6.0.1 + * @version v6.1.0 * @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):(t=t||self,function(){var e=t.Toolkit,n=t.Toolkit={};i(n,t._,t.Backbone,t.Marionette),n.noConflict=function(){return t.Toolkit=e,n}}())}(this,function(t,i,e,n){"use strict";i=i&&i.hasOwnProperty("default")?i.default:i,e=e&&e.hasOwnProperty("default")?e.default:e;var s=["StateModel","stateEvents"],r={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,s),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()}},o=["childApps","childAppOptions"],h={_initChildApps:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};this._childApps={},this.mergeOptions(t,o);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},_startChildApp:function(t,e){var n=this._getChildStartOpts(t);return t.start(i.extend(n,e))},_shouldActWithRestart:function(t,e){if(!this._isRestarting)return!0;var n=i.result(t,"restartWithParent");return!0===n||(!(!1===n||!i.result(t,e))||void 0)},_startChildApps:function(){var t=this;i.each(this._childApps,function(e){t._shouldActWithRestart(e,"startWithParent")&&(t._isRestarting||i.result(e,"startWithParent"))&&t._startChildApp(e)})},_stopChildApps:function(){var t=this;i.each(this._childApps,function(e){t._shouldActWithRestart(e,"stopWithParent")&&(t._isRestarting||i.result(e,"stopWithParent"))&&e.stop()})},startChildApp:function(t,i){var e=this.getChildApp(t);return this._startChildApp(e,i)},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 new t(e=i.extend({},this.childAppOptions,e))},_ensureAppIsUnique:function(t){if(this._childApps[t])throw new Error('A child App with name "'.concat(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")&&this._startChildApp(s),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}},a={_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)}},p={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=new Array(n>1?n-1:0),r=1;r0&&void 0!==arguments[0]?arguments[0]:{};this.mergeOptions(t,u),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.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},finallyStart:function(){this._startChildApps(),this.triggerMethod.apply(this,["start"].concat(Array.prototype.slice.call(arguments)))},triggerStart:function(t){this.finallyStart(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=new Array(e>1?e-1:0),s=1;s2?n-2:0),r=2;r0&&void 0!==arguments[0]?arguments[0]:{};this.mergeOptions(t,d),this.options=i.extend({},i.result(this,"options"),t),this._buildEventProxies(),this._initState(t),n.Application.call(this,t),this.delegateStateEvents()},showIn:function(t,i){return this._region=t,this.show(i),this},show:function(t,i){var e=this.getRegion();if(!e)throw new Error("Component has no defined region.");var n=this._getView(t);return this.stopListening(e.currentView,"destroy",this.destroy),this.triggerMethod("before:show",this,n,t,i),this.showView(n,this.mixinRegionOptions(i)),this.listenTo(e.currentView,"destroy",this.destroy),this.triggerMethod("show",this,n,t,i),this},empty:function(){var t=this.getRegion();if(!t)throw new Error("Component has no defined region.");return this.stopListening(t.currentView,"destroy",this.destroy),t.empty(),this},mixinRegionOptions:function(t){var e=i.result(this,"regionOptions");return i.extend({},e,t)},_getView:function(t){var i=this._getViewClass(t),e=this.mixinViewOptions(t),n=this.buildView(i,e);return this._proxyViewEvents(n),n},_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')},mixinViewOptions: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(){if(this._isDestroyed)return this;var t=this.getRegion();return t&&t.empty(),n.Application.prototype.destroy.apply(this,arguments),this}},{setRegion:function(t){this.prototype.region=t}});i.extend(c.prototype,r,p);t.App=l,t.Component=c,t.StateMixin=r,t.VERSION="6.0.1",t.mixinState=function(t){var e=r;t.prototype.StateModel&&(e=i.omit(r,"StateModel")),i.extend(t.prototype,e)},Object.defineProperty(t,"__esModule",{value:!0})}); +!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):(t=t||self,function(){var e=t.Toolkit,n=t.Toolkit={};i(n,t._,t.Backbone,t.Marionette),n.noConflict=function(){return t.Toolkit=e,n}}())}(this,function(t,i,e,n){"use strict";i=i&&i.hasOwnProperty("default")?i.default:i,e=e&&e.hasOwnProperty("default")?e.default:e;var s=["StateModel","stateEvents"],r={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,s),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()}},o=["childApps","childAppOptions"],h={_initChildApps:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};this._childApps={},this.mergeOptions(t,o);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},_startChildApp:function(t,e){var n=this._getChildStartOpts(t);return t.start(i.extend(n,e))},_shouldActWithRestart:function(t,e){if(!this._isRestarting)return!0;var n=i.result(t,"restartWithParent");return!0===n||(!(!1===n||!i.result(t,e))||void 0)},_startChildApps:function(){var t=this;i.each(this._childApps,function(e){t._shouldActWithRestart(e,"startWithParent")&&(t._isRestarting||i.result(e,"startWithParent"))&&t._startChildApp(e)})},_stopChildApps:function(){var t=this;i.each(this._childApps,function(e){t._shouldActWithRestart(e,"stopWithParent")&&(t._isRestarting||i.result(e,"stopWithParent"))&&e.stop()})},startChildApp:function(t,i){var e=this.getChildApp(t);return this._startChildApp(e,i)},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 new t(e=i.extend({},this.childAppOptions,e))},_ensureAppIsUnique:function(t){if(this._childApps[t])throw new Error('A child App with name "'.concat(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")&&this._startChildApp(s),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}},a={_stopRunningEvents:function(){i.each(this._runningEvents,i.bind(function(t){this.off.apply(this,t)},this)),this._runningEvents=[]},_stopRunningListeners:function(){i.each(this._runningListeningTo,i.bind(function(t){this.stopListening.apply(this,t)},this)),this._runningListeningTo=[]},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)}},p={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=new Array(n>1?n-1:0),r=1;r0&&void 0!==arguments[0]?arguments[0]:{};this.mergeOptions(t,u),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.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},finallyStart:function(){this._startChildApps(),this.triggerMethod.apply(this,["start"].concat(Array.prototype.slice.call(arguments)))},triggerStart:function(t){this.finallyStart(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=arguments.length>0&&void 0!==arguments[0]?arguments[0]:this._view,i=this.getRegion(),e=arguments.length,n=new Array(e>1?e-1:0),s=1;s2?n-2:0),r=2;r0&&void 0!==arguments[0]?arguments[0]:{};this.mergeOptions(t,d),this.options=i.extend({},i.result(this,"options"),t),this._buildEventProxies(),this._initState(t),n.Application.call(this,t),this.delegateStateEvents()},showIn:function(t,i,e){return this._region=t,this.show(i,e),this},show:function(t,i){var e=this.getRegion();if(!e)throw new Error("Component has no defined region.");var n=this._getView(t);return this.stopListening(e.currentView,"destroy",this.destroy),this.triggerMethod("before:show",this,n,t,i),this.showView(n,this.mixinRegionOptions(i)),this.listenTo(e.currentView,"destroy",this.destroy),this.triggerMethod("show",this,n,t,i),this},empty:function(){var t=this.getRegion();if(!t)throw new Error("Component has no defined region.");return this.stopListening(t.currentView,"destroy",this.destroy),t.empty(),this},mixinRegionOptions:function(t){var e=i.result(this,"regionOptions");return i.extend({},e,t)},_getView:function(t){var i=this._getViewClass(t),e=this.mixinViewOptions(t),n=this.buildView(i,e);return this._proxyViewEvents(n),n},_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')},mixinViewOptions: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(){if(this._isDestroyed)return this;var t=this.getRegion();return t&&t.empty(),n.Application.prototype.destroy.apply(this,arguments),this}},{setRegion:function(t){this.prototype.region=t}});i.extend(c.prototype,r,p);t.App=l,t.Component=c,t.StateMixin=r,t.VERSION="6.1.0",t.mixinState=function(t){var e=r;t.prototype.StateModel&&(e=i.omit(r,"StateModel")),i.extend(t.prototype,e)},Object.defineProperty(t,"__esModule",{value:!0})}); //# sourceMappingURL=marionette.toolkit.min.js.map diff --git a/dist/marionette.toolkit.min.js.map b/dist/marionette.toolkit.min.js.map index a56b8a0..71015dd 100644 --- a/dist/marionette.toolkit.min.js.map +++ b/dist/marionette.toolkit.min.js.map @@ -1 +1 @@ -{"version":3,"file":"marionette.toolkit.min.js","sources":["../src/mixins/state.js","../src/mixins/child-apps.js","../src/mixins/event-listeners.js","../src/mixins/view-events.js","../src/app.js","../src/component.js","../src/marionette.toolkit.js"],"sourcesContent":["import _ from 'underscore';\nimport Backbone from 'backbone';\n\nconst ClassOptions = [\n 'StateModel',\n 'stateEvents'\n];\n\n/**\n * This provides methods used for keeping state using a Backbone.Model. It's meant to\n * be used with either a Marionette.MnObject or Backbone.View.\n *\n * @mixin\n */\nexport default {\n\n /**\n * The model class for _stateModel.\n * @type {Backbone.Model}\n * @default Backbone.Model\n */\n StateModel: Backbone.Model,\n\n /**\n * @public\n * @method initState\n * @param {Object} [options] - Settings for the StateMixin.\n * @param {Object} [options.stateEvents] - Event hash bound from _stateModel to StateMixin.\n * @param {Backbone.Model} [options.StateModel] - Model class for _stateModel.\n */\n initState(options = {}) {\n this._initState(options);\n this.delegateStateEvents();\n\n return this;\n },\n\n /**\n * @private\n * @method _initState\n * @param {Object} [options] - Settings for the StateMixin.\n */\n _initState(options) {\n // Make defaults available to this\n this.mergeOptions(options, ClassOptions);\n\n // Remove event handlers from previous state\n this._removeEventHandlers();\n\n const StateModel = this._getStateModel(options);\n\n this._stateModel = new StateModel(options.state);\n\n this._setEventHandlers();\n },\n\n /**\n * Bind events from the _stateModel defined in stateEvents hash\n *\n * @public\n * @method delegateStateEvents\n */\n delegateStateEvents() {\n this.undelegateStateEvents();\n this.bindEvents(this._stateModel, _.result(this, 'stateEvents'));\n\n return this;\n },\n\n /**\n * Unbind all entity events on _stateModel\n *\n * @public\n * @method undelegateStateEvents\n */\n undelegateStateEvents() {\n this.unbindEvents(this._stateModel);\n\n return this;\n },\n\n /**\n * Setup destroy event handle\n *\n * @private\n * @method _setEventHandlers\n */\n _setEventHandlers() {\n this.on('destroy', this._destroyState);\n },\n\n /**\n * Clean up destroy event handler, remove any listeners on _stateModel\n *\n * @private\n * @method _removeEventHandlers\n */\n _removeEventHandlers() {\n if (!this._stateModel) {return;}\n\n this.undelegateStateEvents();\n this._stateModel.stopListening();\n this.off('destroy', this._destroyState);\n },\n\n\n /**\n * Get the StateMixin StateModel class.\n * Checks if the `StateModel` is a model class (the common case)\n * Then check if it's a function (which we assume that returns a model class)\n *\n * @private\n * @method _getStateModel\n * @param {Object} [options] - Options that can be used to determine the StateModel.\n * @returns {Backbone.Model}\n */\n _getStateModel(options) {\n if (this.StateModel.prototype instanceof Backbone.Model || this.StateModel === Backbone.Model) {\n return this.StateModel;\n } else if (_.isFunction(this.StateModel)) {\n return this.StateModel.call(this, options);\n }\n\n throw new Error('\"StateModel\" must be a model class or a function that returns a model class');\n },\n\n /**\n * Set a property on the _stateModel.\n *\n * @public\n * @method setState\n * @param {String|Object} key - Attribute name or Hash of any number of key value pairs.\n * @param {*} [value] - Attribute value if key is String, replaces options param otherwise.\n * @param {Object} [options] - Backbone.Model options.\n * @returns {Backbone.Model} - The _stateModel\n */\n setState() {\n return this._stateModel.set.apply(this._stateModel, arguments);\n },\n\n\n /**\n * Reset _stateModel to defined defaults\n *\n * @public\n * @method resetStateDefaults\n * @param {Object} [newState] - Hash of any number of key value pairs.\n * @returns {Backbone.Model|*} - The _stateModel or the attribute value of the _stateModel\n */\n resetStateDefaults() {\n const defaults = _.result(this._stateModel, 'defaults');\n\n return this._stateModel.set(defaults);\n },\n\n /**\n * Get a property from the _stateModel, or return the _stateModel\n *\n * @public\n * @method getState\n * @param {String} [attr] - Attribute name of stateModel.\n * @returns {Backbone.Model|*} - The _stateModel or the attribute value of the _stateModel\n */\n getState(attr) {\n if (!attr) {\n return this._stateModel;\n }\n\n return this._stateModel.get.apply(this._stateModel, arguments);\n },\n\n /**\n * Toggle a property on the _stateModel.\n *\n * @public\n * @method toggleState\n * @param {String} attr - Attribute name of stateModel.\n * @param {val} [value] - Attribute value.\n * @returns {Backbone.Model} - The _stateModel or attribute value.\n */\n toggleState(attr, val) {\n if (arguments.length > 1) {return this._stateModel.set(attr, !!val);}\n\n return this._stateModel.set(attr, !this._stateModel.get(attr));\n },\n\n /**\n * Check if _stateModel has a property\n *\n * @public\n * @method hasState\n * @param {String} [attr] - Attribute name of stateModel.\n * @returns {Boolean}\n */\n hasState(attr) {\n return this._stateModel.has(attr);\n },\n\n /**\n * Clean up any listeners on the _stateModel.\n *\n * @private\n * @method _destroyState\n */\n _destroyState() {\n this._stateModel.stopListening();\n }\n};\n","import _ from 'underscore';\n\nconst ClassOptions = [\n 'childApps',\n 'childAppOptions'\n];\n\n/**\n * This provides methods used for \"App Manager\" functionality - the adding and removing child `App`s. It's not meant to\n * be used directly.\n *\n * @mixin\n */\nexport default {\n\n /**\n * @private\n * @method _initChildApps\n * @constructs ChildApps\n * @param {Object} [options] - Settings for the ChildApps.\n * @param {Object} [options.childApps] - Hash for setting up child apps.\n * @param {Object} [options.childAppOptions] - Hash of options passed to every child app.\n *\n * ```js\n * childApps: {\n * appName: {\n * AppClass: MyChildAppClass,\n * fooOption: true,\n * startWithParent: true\n * },\n * barApp: MyOtherChildAppClass\n * }\n * ```\n */\n _initChildApps(options = {}) {\n this._childApps = {};\n\n this.mergeOptions(options, ClassOptions);\n\n let childApps = this.childApps;\n\n if (childApps) {\n if (_.isFunction(childApps)) {\n childApps = childApps.call(this, options);\n }\n\n this.addChildApps(childApps);\n }\n },\n\n /**\n * Finds `regionName` and `getOptions` for the childApp\n *\n * @private\n * @method _getChildStartOpts\n */\n _getChildStartOpts(childApp) {\n const tkOpts = childApp._tkOpts || {};\n\n const opts = {\n region: this.getRegion(tkOpts.regionName)\n };\n\n _.each(tkOpts.getOptions, opt => {\n opts[opt] = this.getOption(opt);\n });\n\n return opts;\n },\n\n /**\n * Starts a `childApp`\n *\n * @private\n * @method _startChildApp\n */\n _startChildApp(childApp, options) {\n const opts = this._getChildStartOpts(childApp);\n return childApp.start(_.extend(opts, options));\n },\n\n /**\n * Handles explicit boolean values of restartWithParent\n * restartWithParent === false does nothing\n *\n * @private\n * @method _shouldStartWithRestart\n */\n _shouldActWithRestart(childApp, action) {\n if (!this._isRestarting) {return true;}\n const restartWithParent = _.result(childApp, 'restartWithParent');\n if (restartWithParent === true) {return true;}\n if (restartWithParent !== false && _.result(childApp, action)) {return true;}\n },\n\n /**\n * Starts `childApps` if allowed by child\n *\n * @private\n * @method _startChildApps\n */\n _startChildApps() {\n const action = 'startWithParent';\n _.each(this._childApps, childApp => {\n if (!this._shouldActWithRestart(childApp, action)) {return;}\n if (!this._isRestarting && !_.result(childApp, action)) {return;}\n this._startChildApp(childApp);\n });\n },\n\n /**\n * Stops `childApps` if allowed by child\n *\n * @private\n * @method _stopChildApps\n */\n _stopChildApps() {\n const action = 'stopWithParent';\n _.each(this._childApps, childApp => {\n if (!this._shouldActWithRestart(childApp, action)) {return;}\n if (!this._isRestarting && !_.result(childApp, action)) {return;}\n childApp.stop();\n });\n },\n\n /**\n * Starts `childApp`\n *\n * @param {String} appName - Name of childApp to start\n * @param {Object} options - Start options for app\n * @public\n * @method startChildApp\n */\n startChildApp(appName, options) {\n const childApp = this.getChildApp(appName);\n return this._startChildApp(childApp, options);\n },\n\n /**\n * Stops `childApp`\n *\n * @param {String} appName - Name of childApp to stop\n * @param {Object} options - Stop options for app\n * @public\n * @method stopChildApp\n */\n stopChildApp(appName, options) {\n return this.getChildApp(appName).stop(options);\n },\n\n /**\n * Destroys `childApps` if allowed by child\n *\n * @private\n * @method _destroyChildApps\n */\n _destroyChildApps() {\n _.each(this._childApps, function(childApp) {\n if (!_.result(childApp, 'preventDestroy')) {\n childApp.destroy();\n }\n });\n },\n\n /**\n * Internal helper to instantiate and `App` from on `Object`\n *\n * @private\n * @method _buildAppFromObject\n * @param {Object} appConfig - `AppClass` and any other option for the `App`\n * @returns {App}\n */\n _buildAppFromObject(appConfig) {\n const AppClass = appConfig.AppClass;\n const options = _.omit(appConfig, 'AppClass', 'regionName', 'getOptions');\n\n const app = this.buildApp(AppClass, options);\n\n app._tkOpts = _.pick(appConfig, 'regionName', 'getOptions');\n\n return app;\n },\n\n /**\n * Helper for building an App and return it\n *\n * @private\n * @method _buildApp\n * @param {App} AppClass - An App Class\n * @param {Object} AppClass - Optionally passed as an appConfig Object\n * @param {Object} [options] - options for the AppClass\n * @returns {App}\n */\n _buildApp(AppClass, options) {\n if (_.isFunction(AppClass)) {\n return this.buildApp(AppClass, options);\n }\n if (_.isObject(AppClass)) {\n return this._buildAppFromObject(AppClass);\n }\n },\n\n /**\n * Build an App and return it\n * Override for dynamic App building\n *\n * @public\n * @method buildApp\n * @param {App} [AppClass] - An App Class\n * @param {Object} [options] - options for the AppClass\n * @returns {App}\n */\n buildApp(AppClass, options) {\n // options on childApp definition supersede childAppOptions\n options = _.extend({}, this.childAppOptions, options);\n\n return new AppClass(options);\n },\n\n /**\n * Internal helper to verify `appName` is unique and not in use\n *\n * @private\n * @method _ensureAppIsUnique\n * @param {String} appName - Name of app to test\n * @throws DuplicateChildAppError - Thrown if `App` already has an `appName` registered\n */\n _ensureAppIsUnique(appName) {\n if (this._childApps[appName]) {\n throw new Error(`A child App with name \"${ appName }\" has already been added.`);\n }\n },\n\n /**\n * Add child `App`s to this `App`\n *\n * @public\n * @method addChildApps\n * @param {Object} childApps - Hash of names and `AppClass` or `appConfig`\n */\n addChildApps(childApps) {\n _.each(childApps, _.bind(function(childApp, appName) {\n this.addChildApp(appName, childApp);\n }, this));\n },\n\n /**\n * Build's childApp and registers it with this App\n * Starts the childApp, if this app is running and child is `startWithParent`\n *\n * @public\n * @method addChildApp\n * @param {String} appName - Name of App to register\n * @param {App} AppClass - An App Class\n * @param {Object} AppClass - Optionally passed as an appConfig Object\n * @param {Object} [options] - options for the AppClass\n * @throws AddChildAppError - Thrown if no childApp could be built from params\n * @returns {App}\n */\n addChildApp(appName, AppClass, options) {\n this._ensureAppIsUnique(appName);\n\n const childApp = this._buildApp(AppClass, options);\n\n if (!childApp) {\n throw new Error('App build failed. Incorrect configuration.');\n }\n\n childApp._name = appName;\n\n this._childApps[appName] = childApp;\n\n // When the app is destroyed remove the cached app.\n // Listener setup relative to the childApp's running state (using _on)\n childApp._on('destroy', _.partial(this._removeChildApp, appName), this);\n\n if (this.isRunning() && _.result(childApp, 'startWithParent')) {\n this._startChildApp(childApp);\n }\n\n return childApp;\n },\n\n /**\n * Returns registered child `App`s name\n *\n * @public\n * @method getName\n * @returns {String}\n */\n getName() {\n return this._name;\n },\n\n\n /**\n * Returns registered child `App`s array\n *\n * @public\n * @method getChildApps\n * @returns {Array}\n */\n getChildApps() {\n return _.clone(this._childApps);\n },\n\n /**\n * Returns registered child `App`\n *\n * @public\n * @method getChildApp\n * @param {String} appName - Name of App to retrieve\n * @returns {App}\n */\n getChildApp(appName) {\n return this._childApps[appName];\n },\n\n /**\n * Internal helper. Unregisters child `App`\n *\n * @private\n * @method _removeChildApp\n * @param {String} appName - Name of App to unregister\n * @returns {App}\n */\n _removeChildApp(appName) {\n delete this._childApps[appName]._name;\n delete this._childApps[appName];\n },\n\n /**\n * Removes all childApps and returns them.\n * The return is useful if any app is using `preventDestroy`\n *\n * @public\n * @method removeChildApps\n * @returns {Array}\n */\n removeChildApps() {\n const childApps = this.getChildApps();\n\n _.each(this._childApps, _.bind(function(childApp, appName) {\n this.removeChildApp(appName);\n }, this));\n\n return childApps;\n },\n\n /**\n * Destroys or removes registered child `App` by name\n * depending on `preventDestroy`\n *\n * @public\n * @method removeChildApp\n * @param {String} appName - Name of App to destroy\n * @param {Object} [options.preventDestroy] - Flag to remove but prevent App destroy\n * @returns {App}\n */\n removeChildApp(appName, options) {\n options = _.extend({}, options);\n\n const childApp = this.getChildApp(appName);\n\n if (!childApp) {\n return;\n }\n\n // if preventDestroy simply unregister the child app\n if (options.preventDestroy || _.result(childApp, 'preventDestroy')) {\n this._removeChildApp(appName);\n } else {\n childApp.destroy();\n }\n\n return childApp;\n }\n};\n","import _ from 'underscore';\nimport { MnObject } from 'backbone.marionette';\n\n/**\n * This provides methods used for registering events while App is running and cleans them up at `onStop`. It's not meant to\n * be used directly.\n *\n * @mixin\n */\n\nexport default {\n /**\n * Internal method to stop any registered events.\n *\n * @private\n * @method _stopRunningEvents\n */\n _stopRunningEvents() {\n _.each(this._runningEvents, _.bind(function(args) {\n this.off.apply(this, args);\n }, this));\n },\n\n /**\n * Internal method to stop any registered listeners.\n *\n * @private\n * @method _stopRunningListeners\n */\n _stopRunningListeners() {\n _.each(this._runningListeningTo, _.bind(function(args) {\n this.stopListening.apply(this, args);\n }, this));\n },\n\n /**\n * Overrides `Backbone.Event.on()`\n * If this `App` is running it will register the event for removal `onStop`\n *\n * @public\n * @method on\n * @returns {EventListeners}\n */\n on() {\n if (this._isRunning) {\n this._runningEvents = (this._runningEvents || []);\n this._runningEvents.push(arguments);\n }\n\n return MnObject.prototype.on.apply(this, arguments);\n },\n\n /**\n * Keep a copy of non-running on for internal use\n *\n * @private\n * @method _on\n * @returns {EventListeners}\n */\n _on: MnObject.prototype.on,\n\n /**\n * Overrides `Backbone.Event.listenTo()`\n * If this `App` is running it will register the listener for removal `onStop`\n *\n * @public\n * @method listenTo\n * @returns {EventListeners}\n */\n listenTo() {\n if (this._isRunning) {\n this._runningListeningTo = (this._runningListeningTo || []);\n this._runningListeningTo.push(arguments);\n }\n return MnObject.prototype.listenTo.apply(this, arguments);\n },\n\n /**\n * Keep a copy of non-running on for internal use\n *\n * @private\n * @method _listenTo\n * @returns {EventListeners}\n */\n _listenTo: MnObject.prototype.listenTo,\n\n /**\n * Overrides `Backbone.Event.listenToOnce()`\n * If this `App` is running it will register the listener for removal `onStop`\n *\n * @public\n * @method listenToOnce\n * @returns {EventListeners}\n */\n listenToOnce() {\n if (this._isRunning) {\n this._runningListeningTo = (this._runningListeningTo || []);\n this._runningListeningTo.push(arguments);\n }\n\n return MnObject.prototype.listenToOnce.apply(this, arguments);\n }\n};\n","import _ from 'underscore';\n\nexport default {\n /**\n * Used as the prefix for events forwarded from\n * the component's view to the component\n * @type {String}\n * @default false\n */\n viewEventPrefix: false,\n\n /**\n * Constructs hashes and options for view event proxy\n *\n * @private\n * @method _buildEventProxies\n */\n _buildEventProxies() {\n const viewEvents = _.result(this, 'viewEvents') || {};\n this._viewEvents = this.normalizeMethods(viewEvents);\n this._viewTriggers = _.result(this, 'viewTriggers') || {};\n this._viewEventPrefix = _.result(this, 'viewEventPrefix');\n },\n\n /**\n * Proxies the ViewClass's viewEvents to the Component itself\n * Similar to CollectionView childEvents\n * (http://marionettejs.com/docs/v2.3.2/marionette.collectionview.html#collectionviews-childevents)\n *\n * @private\n * @method _proxyViewEvents\n * @param {Mn.View|Mn.CollectionView} view -\n * The instantiated ViewClass.\n */\n _proxyViewEvents(view) {\n this.listenTo(view, 'all', this._childViewEventHandler);\n },\n\n /**\n * Event handler for view proxy\n * Similar to CollectionView childEvents\n * (http://marionettejs.com/docs/v2.3.2/marionette.collectionview.html#collectionviews-childevents)\n *\n * @private\n * @method _childViewEventHandler\n * @param {String} - event name\n */\n _childViewEventHandler(eventName, ...args) {\n const viewEvents = this._viewEvents;\n\n if (_.isFunction(viewEvents[eventName])) {\n viewEvents[eventName].apply(this, args);\n }\n\n // use the parent view's proxyEvent handlers\n const viewTriggers = this._viewTriggers;\n\n // Call the event with the proxy name on the parent layout\n if (_.isString(viewTriggers[eventName])) {\n this.triggerMethod(viewTriggers[eventName], ...args);\n }\n\n const prefix = this._viewEventPrefix;\n\n if (prefix !== false) {\n const viewEventName = `${ prefix }:${ eventName }`;\n\n this.triggerMethod(viewEventName, ...args);\n }\n }\n};\n","import _ from 'underscore';\nimport { Application } from 'backbone.marionette';\nimport StateMixin from './mixins/state';\nimport ChildAppsMixin from './mixins/child-apps';\nimport EventListenersMixin from './mixins/event-listeners';\nimport ViewEventsMixin from './mixins/view-events';\n\nconst ClassOptions = [\n 'startWithParent',\n 'restartWithParent',\n 'stopWithParent',\n 'startAfterInitialized',\n 'preventDestroy',\n 'StateModel',\n 'stateEvents',\n 'viewEventPrefix',\n 'viewEvents',\n 'viewTriggers'\n];\n\n/**\n * Marionette.Application with an `initialize` / `start` / `stop` / `destroy` lifecycle.\n *\n * @public\n * @class App\n * @memberOf Toolkit\n * @memberOf Marionette\n */\nconst App = Application.extend({\n\n /**\n * Internal flag indiciate when `App` has started but has not yet stopped.\n *\n * @private\n * @type {Boolean}\n * @default false\n */\n _isRunning: false,\n\n /**\n * Internal flag indiciate when `App` is in the process of stopping then starting.\n *\n * @private\n * @type {Boolean}\n * @default false\n */\n _isRestarting: false,\n\n /**\n * Set to true if a parent `App` should not be able to destroy this `App`.\n *\n * @type {Boolean|Function}\n * @default false\n */\n preventDestroy: false,\n\n /**\n * Set to true if `App` should be started after it is initialized.\n *\n * @type {Boolean|Function}\n * @default false\n */\n startAfterInitialized: false,\n\n /**\n * Set to true if `App` should be started after its parent starts.\n *\n * @type {Boolean|Function}\n * @default false\n */\n startWithParent: false,\n\n /**\n * Set to false if `App` should not stop after its parent stops.\n *\n * @type {Boolean|Function}\n * @default true\n */\n stopWithParent: true,\n\n\n /**\n * Set this to determine if a parent `App` should maintain the child's\n * lifecycle during a restart.\n *\n * @type {Boolean|Function}\n * @default null\n */\n restartWithParent: null,\n\n /**\n * @public\n * @constructs App\n * @param {Object} [options] - Settings for the App.\n * @param {Boolean} [options.startWithParent]\n * @param {Boolean} [options.restartWithParent]\n * @param {Boolean} [options.stopWithParent]\n * @param {Boolean} [options.startAfterInitialized]\n * @param {Boolean} [options.preventDestroy]\n * @param {Object} [options.state] - Attributes to set on the state model.\n */\n constructor(options = {}) {\n this.mergeOptions(options, ClassOptions);\n\n this.options = _.extend({}, _.result(this, 'options'), options);\n\n // ChildAppsMixin\n this._initChildApps(options);\n\n Application.call(this, options);\n\n if (_.result(this, 'startAfterInitialized')) {\n this.start(options);\n }\n },\n\n /**\n * Internal helper to verify if `App` has been destroyed\n *\n * @private\n * @method _ensureAppIsIntact\n * @memberOf App\n * @throws AppDestroyedError - Thrown if `App` has already been destroyed\n */\n _ensureAppIsIntact() {\n if (this._isDestroyed) {\n throw new Error('App has already been destroyed and cannot be used.');\n }\n },\n\n /**\n * Gets the value of internal `_isRunning` flag\n *\n * @public\n * @method isRunning\n * @memberOf App\n * @returns {Boolean}\n */\n isRunning() {\n return this._isRunning;\n },\n\n /**\n * Gets the value of internal `_isRestarting` flag\n *\n * @public\n * @method isRestarting\n * @memberOf App\n * @returns {Boolean}\n */\n isRestarting() {\n return this._isRestarting;\n },\n\n /**\n * Sets the app lifecycle to running.\n *\n * @public\n * @method start\n * @memberOf App\n * @param {Object} [options] - Settings for the App passed through to events\n * @event App#before:start - passes options\n * @returns {App}\n */\n start(options = {}) {\n this._ensureAppIsIntact();\n\n if (this._isRunning) {\n return this;\n }\n\n if (options.region) {\n this.setRegion(options.region);\n }\n\n if (options.view) {\n this.setView(options.view);\n }\n\n // StateMixin\n this._initState(options);\n\n // ViewEventMixin\n this._buildEventProxies();\n\n this.triggerMethod('before:start', options);\n\n this._isRunning = true;\n\n this._bindRunningEvents();\n\n this.triggerStart(options);\n\n return this;\n },\n\n /**\n * Sets up region, view, and state events.\n * To only be called after `isRunning` is true\n *\n * @private\n * @method _bindRunningEvents\n * @memberOf App\n */\n _bindRunningEvents() {\n if (this._region) {\n this._regionEventMonitor();\n }\n\n if (this._view) {\n this._proxyViewEvents(this._view);\n }\n\n // StateMixin\n this.delegateStateEvents();\n },\n\n /**\n * Sets the app lifecycle to not running\n * then sets the app lifecycle to running with ending state\n *\n * @public\n * @method restart\n * @memberOf App\n * @returns {App}\n */\n restart() {\n const state = this.getState().attributes;\n\n this._isRestarting = true;\n this.stop().start({ state });\n this._isRestarting = false;\n\n return this;\n },\n\n /**\n * Starts children and triggers start event\n * For calling within `triggerStart`\n *\n * @public\n * @method finallyStart\n * @memberOf App\n * @event App#start - passes any arguments\n * @returns\n */\n finallyStart() {\n this._startChildApps();\n this.triggerMethod('start', ...arguments);\n },\n\n /**\n * Triggers start event via finallyStart.\n * Override to introduce async start\n *\n * @public\n * @method triggerStart\n * @memberOf App\n * @param {Object} [options] - Settings for the App passed through to events\n * @returns\n */\n triggerStart(options) {\n this.finallyStart(options);\n },\n\n /**\n * Sets the app lifecycle to not running.\n * Removes any listeners added during the running state\n *\n * @public\n * @method stop\n * @memberOf App\n * @param {Object} [options] - Settings for the App passed through to events\n * @event App#before:stop - passes options\n * @event App#stop - passes options\n * @returns {App}\n */\n stop(options) {\n if (!this._isRunning) {\n return this;\n }\n\n this.triggerMethod('before:stop', options);\n\n this._stopChildApps();\n\n this._isRunning = false;\n\n this.triggerMethod('stop', options);\n\n // Running events are cleaned up after stop so that\n // `stop` event handlers still fire\n this._stopRunningListeners();\n this._stopRunningEvents();\n\n return this;\n },\n\n /**\n * Stops the `App` and sets it destroyed.\n *\n * @public\n * @method destroy\n * @memberOf App\n */\n destroy() {\n if (this._isDestroyed) {\n return this;\n }\n\n this.stop();\n\n this._removeView();\n\n this._destroyChildApps();\n\n Application.prototype.destroy.apply(this, arguments);\n\n return this;\n },\n\n /**\n * Set the Application's Region\n *\n * @public\n * @method setRegion\n * @memberOf App\n * @param {Region} [region] - Region to use with the app\n * @returns {Region}\n */\n setRegion(region) {\n if (this._region) {\n this.stopListening(this._region);\n }\n\n this._region = region;\n\n if (region.currentView) {\n this.setView(region.currentView);\n }\n\n if (this._isRunning) {\n this._regionEventMonitor();\n }\n\n return region;\n },\n\n /**\n * Monitors the apps region before:show event so the region's view\n * is available to the app\n *\n * @private\n * @method _regionEventMonitor\n * @memberOf App\n */\n _regionEventMonitor() {\n this.listenTo(this._region, {\n 'before:show': this._onBeforeShow,\n 'empty': this._onEmpty\n });\n },\n\n /**\n * Region monitor handler which sets the app's view to the region's view\n *\n * @private\n * @method _onBeforeShow\n * @memberOf App\n */\n _onBeforeShow(region, view) {\n this.setView(view);\n },\n\n /**\n * Region monitor handler which empties the region's view\n *\n * @private\n * @method _onEmpty\n * @memberOf App\n */\n _onEmpty(region, view) {\n if (view !== this._view) {return;}\n\n this._removeView();\n },\n\n /**\n * Region monitor handler which deletes the region's view and listeners to view\n *\n * @private\n * @method _removeView\n * @memberOf App\n */\n _removeView() {\n if (this._view) {\n this.stopListening(this._view);\n delete this._view;\n }\n },\n\n /**\n * Get the Application's Region or\n * Get a region from the Application's View\n *\n * @public\n * @method getRegion\n * @memberOf App\n * @param {String} [regionName] - Optional regionName to get from the view\n * @returns {Region}\n */\n getRegion(regionName) {\n if (!regionName) {\n return this._region;\n }\n\n return this.getView().getRegion(regionName);\n },\n\n /**\n * Set the Application's View\n *\n * @public\n * @method setView\n * @memberOf App\n * @param {View} [view] - View to use with the app\n * @returns {View}\n */\n setView(view) {\n if (this._view === view) {\n return view;\n }\n\n if (this._view) {\n this.stopListening(this._view);\n }\n\n this._view = view;\n\n // ViewEventsMixin\n if (this._isRunning) {\n this._proxyViewEvents(view);\n }\n\n // Internal non-running listener\n this._listenTo(this._view, 'destroy', this._removeView);\n\n return view;\n },\n\n /**\n * Get the Application's View\n *\n * @public\n * @method getView\n * @memberOf App\n * @returns {View}\n */\n getView() {\n return this._view || this._region && this._region.currentView;\n },\n\n /**\n * Shows a view in the Application's region\n *\n * @public\n * @method showView\n * @param {View} view - Child view instance defaults to App's view\n * @param {...args} Additional args that get passed along\n * @returns {View}\n */\n showView(view = this._view, ...args) {\n this.getRegion().show(view, ...args);\n\n return view;\n },\n\n /**\n * Shows a view in the region of the app's view\n *\n * @public\n * @method showChildView\n * @param {String} regionName - Name of region to show in\n * @param {View} view - Child view instance\n * @param {...args} Additional args that get passed along\n * @returns {View} - Child view instance\n */\n showChildView(regionName, view, ...args) {\n this.getView().showChildView(regionName, view, ...args);\n\n return view;\n },\n\n /**\n * Returns view from the App view by region name.\n *\n * @public\n * @method getChildView\n * @param {String} regionName - Name of region to get view from\n * @returns {View}\n */\n getChildView(regionName) {\n return this.getView().getChildView(regionName);\n }\n});\n\n_.extend(App.prototype, StateMixin, ChildAppsMixin, EventListenersMixin, ViewEventsMixin);\n\nexport default App;\n","import _ from 'underscore';\nimport Backbone from 'backbone';\nimport { Application, View } from 'backbone.marionette';\nimport StateMixin from './mixins/state';\nimport ViewEventsMixin from './mixins/view-events';\n\nconst ClassOptions = [\n 'regionOptions',\n 'ViewClass',\n 'viewEventPrefix',\n 'viewEvents',\n 'viewTriggers',\n 'viewOptions'\n];\n\n/**\n * Reusable Marionette.MnObject with View management boilerplate\n *\n * @public\n * @class Component\n * @memberOf Toolkit\n * @memberOf Marionette\n */\nconst Component = Application.extend({\n\n /**\n * The view class to be managed.\n * @type {Mn.View|Mn.CollectionView}\n * @default Marionette.View\n */\n ViewClass: View,\n\n /**\n * @public\n * @constructs Component\n * @param {Object} [options] - Settings for the component.\n * @param {Object} [options.state] - Attributes to set on the state model.\n * @param {Mn.View|Mn.CollectionView} [options.ViewClass]\n * - The view class to be managed.\n * @param {String} [options.viewEventPrefix]\n * - Used as the prefix for events forwarded from the component's view to the component\n * @param {Object} [options.viewOptions] - Options hash passed to an instantiated ViewClass.\n * @param {Marionette.Region} [options.region] - The region to show the component in.\n */\n constructor(options = {}) {\n // Make defaults available to this\n this.mergeOptions(options, ClassOptions);\n\n this.options = _.extend({}, _.result(this, 'options'), options);\n\n // ViewEventMixin\n this._buildEventProxies();\n\n // StateMixin\n this._initState(options);\n\n Application.call(this, options);\n\n // StateMixin\n this.delegateStateEvents();\n },\n\n /**\n * Set the Component's region and then show it.\n *\n * @public\n * @method showIn\n * @memberOf Component\n * @param {Marionette.Region} region - The region for the component\n * @param {Object} [viewOptions] - Options hash mixed into the instantiated ViewClass.\n * @returns {Component}\n */\n showIn(region, viewOptions) {\n this._region = region;\n\n this.show(viewOptions);\n\n return this;\n },\n\n /**\n * Show the Component in its region.\n *\n * @public\n * @event Component#before:show\n * @event Component#show\n * @throws ComponentRegionError - Thrown if component has no defined region.\n * @method show\n * @param {Object} [viewOptions] - Options hash mixed into the instantiated ViewClass.\n * @param {Object} [regionOptions] - Options hash passed to the region on show.\n * @memberOf Component\n * @returns {Component}\n */\n show(viewOptions, regionOptions) {\n const region = this.getRegion();\n\n if (!region) {\n throw new Error('Component has no defined region.');\n }\n\n const view = this._getView(viewOptions);\n\n this.stopListening(region.currentView, 'destroy', this.destroy);\n\n this.triggerMethod('before:show', this, view, viewOptions, regionOptions);\n\n this.showView(view, this.mixinRegionOptions(regionOptions));\n\n this.listenTo(region.currentView, 'destroy', this.destroy);\n\n this.triggerMethod('show', this, view, viewOptions, regionOptions);\n\n return this;\n },\n\n /**\n * Empty the Components region without destroying it\n *\n * @public\n * @throws ComponentRegionError - Thrown if component has no defined region.\n * @method empty\n * @memberOf Component\n * @returns {Component}\n */\n empty() {\n const region = this.getRegion();\n\n if (!region) {\n throw new Error('Component has no defined region.');\n }\n\n this.stopListening(region.currentView, 'destroy', this.destroy);\n\n region.empty();\n\n return this;\n },\n\n /**\n * Mixin regionOptions\n *\n * @public\n * @abstract\n * @method mixinRegionOptions\n * @memberOf Component\n * @param {Object} [options] - Additional options to mixin\n * @returns {Object}\n */\n mixinRegionOptions(options) {\n const regionOptions = _.result(this, 'regionOptions');\n\n return _.extend({}, regionOptions, options);\n },\n\n /**\n * Get the Component view instance.\n *\n * @private\n * @method _getView\n * @memberOf Component\n * @param {Object} [options] - Options that can be used to determine the ViewClass.\n * @returns {View}\n */\n _getView(options) {\n const ViewClass = this._getViewClass(options);\n\n const viewOptions = this.mixinViewOptions(options);\n\n const view = this.buildView(ViewClass, viewOptions);\n\n // ViewEventMixin\n this._proxyViewEvents(view);\n\n return view;\n },\n\n /**\n * Get the Component ViewClass class.\n * Checks if the `ViewClass` is a view class (the common case)\n * Then check if it's a function (which we assume that returns a view class)\n *\n * @private\n * @method _getViewClass\n * @memberOf Component\n * @param {Object} [options] - Options that can be used to determine the ViewClass.\n * @returns {View}\n */\n _getViewClass(options = {}) {\n const ViewClass = this.ViewClass;\n\n if (ViewClass.prototype instanceof Backbone.View || ViewClass === Backbone.View) {\n return ViewClass;\n } else if (_.isFunction(ViewClass)) {\n return ViewClass.call(this, options);\n }\n\n throw new Error('\"ViewClass\" must be a view class or a function that returns a view class');\n },\n\n /**\n * Mixin initial State with any other viewOptions\n *\n * @public\n * @abstract\n * @method mixinViewOptions\n * @memberOf Component\n * @param {Object} [options] - Additional options to mixin\n * @returns {Object}\n */\n mixinViewOptions(options) {\n const viewOptions = _.result(this, 'viewOptions');\n\n return _.extend({ state: this.getState().attributes }, viewOptions, options);\n },\n\n /**\n * Builds the view class with options\n * If you need a dynamic ViewClass override this function\n *\n * @public\n * @abstract\n * @method buildView\n * @memberOf Component\n * @param {Mn.View|Mn.CollectionView} ViewClass -\n * The view class to instantiate.\n * @param {Object} [viewOptions] - Options to pass to the View\n * @returns {Mn.View|Mn.CollectionView}\n */\n buildView(ViewClass, viewOptions) {\n return new ViewClass(viewOptions);\n },\n\n /**\n * Empty the region and destroy the component.\n *\n * @public\n * @method destroy\n * @param {Object} [options] - Options passed to Mn.Application `destroy`\n * @memberOf Component\n */\n destroy() {\n if (this._isDestroyed) {\n return this;\n }\n\n const region = this.getRegion();\n if (region) {region.empty();}\n\n Application.prototype.destroy.apply(this, arguments);\n\n return this;\n }\n}, {\n /**\n * Sets the region for a Component Class\n *\n * @public\n * @method setRegion\n * @param {Marionette.Region} - region definition for instantiated components\n * @memberOf Component.prototype\n */\n setRegion(region) {\n this.prototype.region = region;\n }\n});\n\n_.extend(Component.prototype, StateMixin, ViewEventsMixin);\n\nexport default Component;\n","import _ from 'underscore';\n\nimport StateMixin from './mixins/state';\nimport App from './app';\nimport Component from './component';\n\nimport { version as VERSION } from '../package.json';\n\n/**\n * @module Toolkit\n */\n\nfunction mixinState(classDefinition) {\n let _StateMixin = StateMixin;\n\n if (classDefinition.prototype.StateModel) {\n _StateMixin = _.omit(StateMixin, 'StateModel');\n }\n\n _.extend(classDefinition.prototype, _StateMixin);\n}\n\nexport {\n App,\n Component,\n mixinState,\n StateMixin,\n VERSION\n};\n"],"names":["ClassOptions","StateModel","Backbone","Model","initState","options","_initState","delegateStateEvents","this","mergeOptions","_removeEventHandlers","_getStateModel","_stateModel","state","_setEventHandlers","undelegateStateEvents","bindEvents","_","result","unbindEvents","on","_destroyState","stopListening","off","prototype","isFunction","call","Error","setState","set","apply","arguments","resetStateDefaults","defaults","getState","attr","get","toggleState","val","length","hasState","has","_initChildApps","_childApps","childApps","addChildApps","_getChildStartOpts","childApp","tkOpts","_tkOpts","opts","region","getRegion","regionName","each","getOptions","opt","_this","getOption","_startChildApp","start","extend","_shouldActWithRestart","action","_isRestarting","restartWithParent","_startChildApps","_this2","_stopChildApps","_this3","stop","startChildApp","appName","getChildApp","stopChildApp","_destroyChildApps","destroy","_buildAppFromObject","appConfig","AppClass","omit","app","buildApp","pick","_buildApp","isObject","childAppOptions","_ensureAppIsUnique","bind","addChildApp","_name","_on","partial","_removeChildApp","isRunning","getName","getChildApps","clone","removeChildApps","removeChildApp","preventDestroy","_stopRunningEvents","_runningEvents","args","_stopRunningListeners","_runningListeningTo","_isRunning","push","MnObject","listenTo","_listenTo","listenToOnce","viewEventPrefix","_buildEventProxies","viewEvents","_viewEvents","normalizeMethods","_viewTriggers","_viewEventPrefix","_proxyViewEvents","view","_childViewEventHandler","eventName","viewTriggers","isString","triggerMethod","prefix","viewEventName","App","Application","startAfterInitialized","startWithParent","stopWithParent","constructor","_ensureAppIsIntact","_isDestroyed","isRestarting","setRegion","setView","_bindRunningEvents","triggerStart","_region","_regionEventMonitor","_view","restart","attributes","finallyStart","_removeView","currentView","_onBeforeShow","_onEmpty","getView","showView","show","showChildView","getChildView","StateMixin","ChildAppsMixin","EventListenersMixin","ViewEventsMixin","Component","ViewClass","View","showIn","viewOptions","regionOptions","_getView","mixinRegionOptions","empty","_getViewClass","mixinViewOptions","buildView","classDefinition","_StateMixin"],"mappings":";;;;;;ygBAGA,IAAMA,EAAe,CACnB,aACA,iBASa,CAObC,WAAYC,EAASC,MASrBC,yBAAUC,yDAAU,eACbC,WAAWD,QACXE,sBAEEC,MAQTF,oBAAWD,QAEJI,aAAaJ,EAASL,QAGtBU,2BAECT,EAAaO,KAAKG,eAAeN,QAElCO,YAAc,I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IH,EAAUG,IAWvBxF,sBACMpE,KAAK+H,oBACA/H,SAGH2C,EAAS3C,KAAK4C,mBAChBD,GAASA,EAAOqH,QAEpBvC,cAAYzG,UAAUoD,QAAQ9C,MAAMtB,KAAMuB,WAEnCvB,OAER,CASDiI,mBAAUtF,QACH3B,UAAU2B,OAASA,KAI5BlC,EAAE4C,OAAOmG,EAAUxI,UAAWoI,EAAYG,uEC9P1C,SAAoBa,OACdC,EAAcjB,EAEdgB,EAAgBpJ,UAAUvB,aAC5B4K,EAAc5J,EAAE+D,KAAK4E,EAAY,eAGnC3I,EAAE4C,OAAO+G,EAAgBpJ,UAAWqJ"} \ No newline at end of file +{"version":3,"file":"marionette.toolkit.min.js","sources":["../src/mixins/state.js","../src/mixins/child-apps.js","../src/mixins/event-listeners.js","../src/mixins/view-events.js","../src/app.js","../src/component.js","../src/marionette.toolkit.js"],"sourcesContent":["import _ from 'underscore';\nimport Backbone from 'backbone';\n\nconst ClassOptions = [\n 'StateModel',\n 'stateEvents'\n];\n\n/**\n * This provides methods used for keeping state using a Backbone.Model. It's meant to\n * be used with either a Marionette.MnObject or Backbone.View.\n *\n * @mixin\n */\nexport default {\n\n /**\n * The model class for _stateModel.\n * @type {Backbone.Model}\n * @default Backbone.Model\n */\n StateModel: Backbone.Model,\n\n /**\n * @public\n * @method initState\n * @param {Object} [options] - Settings for the StateMixin.\n * @param {Object} [options.stateEvents] - Event hash bound from _stateModel to StateMixin.\n * @param {Backbone.Model} [options.StateModel] - Model class for _stateModel.\n */\n initState(options = {}) {\n this._initState(options);\n this.delegateStateEvents();\n\n return this;\n },\n\n /**\n * @private\n * @method _initState\n * @param {Object} [options] - Settings for the StateMixin.\n */\n _initState(options) {\n // Make defaults available to this\n this.mergeOptions(options, ClassOptions);\n\n // Remove event handlers from previous state\n this._removeEventHandlers();\n\n const StateModel = this._getStateModel(options);\n\n this._stateModel = new StateModel(options.state);\n\n this._setEventHandlers();\n },\n\n /**\n * Bind events from the _stateModel defined in stateEvents hash\n *\n * @public\n * @method delegateStateEvents\n */\n delegateStateEvents() {\n this.undelegateStateEvents();\n this.bindEvents(this._stateModel, _.result(this, 'stateEvents'));\n\n return this;\n },\n\n /**\n * Unbind all entity events on _stateModel\n *\n * @public\n * @method undelegateStateEvents\n */\n undelegateStateEvents() {\n this.unbindEvents(this._stateModel);\n\n return this;\n },\n\n /**\n * Setup destroy event handle\n *\n * @private\n * @method _setEventHandlers\n */\n _setEventHandlers() {\n this.on('destroy', this._destroyState);\n },\n\n /**\n * Clean up destroy event handler, remove any listeners on _stateModel\n *\n * @private\n * @method _removeEventHandlers\n */\n _removeEventHandlers() {\n if (!this._stateModel) {return;}\n\n this.undelegateStateEvents();\n this._stateModel.stopListening();\n this.off('destroy', this._destroyState);\n },\n\n\n /**\n * Get the StateMixin StateModel class.\n * Checks if the `StateModel` is a model class (the common case)\n * Then check if it's a function (which we assume that returns a model class)\n *\n * @private\n * @method _getStateModel\n * @param {Object} [options] - Options that can be used to determine the StateModel.\n * @returns {Backbone.Model}\n */\n _getStateModel(options) {\n if (this.StateModel.prototype instanceof Backbone.Model || this.StateModel === Backbone.Model) {\n return this.StateModel;\n } else if (_.isFunction(this.StateModel)) {\n return this.StateModel.call(this, options);\n }\n\n throw new Error('\"StateModel\" must be a model class or a function that returns a model class');\n },\n\n /**\n * Set a property on the _stateModel.\n *\n * @public\n * @method setState\n * @param {String|Object} key - Attribute name or Hash of any number of key value pairs.\n * @param {*} [value] - Attribute value if key is String, replaces options param otherwise.\n * @param {Object} [options] - Backbone.Model options.\n * @returns {Backbone.Model} - The _stateModel\n */\n setState() {\n return this._stateModel.set.apply(this._stateModel, arguments);\n },\n\n\n /**\n * Reset _stateModel to defined defaults\n *\n * @public\n * @method resetStateDefaults\n * @param {Object} [newState] - Hash of any number of key value pairs.\n * @returns {Backbone.Model|*} - The _stateModel or the attribute value of the _stateModel\n */\n resetStateDefaults() {\n const defaults = _.result(this._stateModel, 'defaults');\n\n return this._stateModel.set(defaults);\n },\n\n /**\n * Get a property from the _stateModel, or return the _stateModel\n *\n * @public\n * @method getState\n * @param {String} [attr] - Attribute name of stateModel.\n * @returns {Backbone.Model|*} - The _stateModel or the attribute value of the _stateModel\n */\n getState(attr) {\n if (!attr) {\n return this._stateModel;\n }\n\n return this._stateModel.get.apply(this._stateModel, arguments);\n },\n\n /**\n * Toggle a property on the _stateModel.\n *\n * @public\n * @method toggleState\n * @param {String} attr - Attribute name of stateModel.\n * @param {val} [value] - Attribute value.\n * @returns {Backbone.Model} - The _stateModel or attribute value.\n */\n toggleState(attr, val) {\n if (arguments.length > 1) {return this._stateModel.set(attr, !!val);}\n\n return this._stateModel.set(attr, !this._stateModel.get(attr));\n },\n\n /**\n * Check if _stateModel has a property\n *\n * @public\n * @method hasState\n * @param {String} [attr] - Attribute name of stateModel.\n * @returns {Boolean}\n */\n hasState(attr) {\n return this._stateModel.has(attr);\n },\n\n /**\n * Clean up any listeners on the _stateModel.\n *\n * @private\n * @method _destroyState\n */\n _destroyState() {\n this._stateModel.stopListening();\n }\n};\n","import _ from 'underscore';\n\nconst ClassOptions = [\n 'childApps',\n 'childAppOptions'\n];\n\n/**\n * This provides methods used for \"App Manager\" functionality - the adding and removing child `App`s. It's not meant to\n * be used directly.\n *\n * @mixin\n */\nexport default {\n\n /**\n * @private\n * @method _initChildApps\n * @constructs ChildApps\n * @param {Object} [options] - Settings for the ChildApps.\n * @param {Object} [options.childApps] - Hash for setting up child apps.\n * @param {Object} [options.childAppOptions] - Hash of options passed to every child app.\n *\n * ```js\n * childApps: {\n * appName: {\n * AppClass: MyChildAppClass,\n * fooOption: true,\n * startWithParent: true\n * },\n * barApp: MyOtherChildAppClass\n * }\n * ```\n */\n _initChildApps(options = {}) {\n this._childApps = {};\n\n this.mergeOptions(options, ClassOptions);\n\n let childApps = this.childApps;\n\n if (childApps) {\n if (_.isFunction(childApps)) {\n childApps = childApps.call(this, options);\n }\n\n this.addChildApps(childApps);\n }\n },\n\n /**\n * Finds `regionName` and `getOptions` for the childApp\n *\n * @private\n * @method _getChildStartOpts\n */\n _getChildStartOpts(childApp) {\n const tkOpts = childApp._tkOpts || {};\n\n const opts = {\n region: this.getRegion(tkOpts.regionName)\n };\n\n _.each(tkOpts.getOptions, opt => {\n opts[opt] = this.getOption(opt);\n });\n\n return opts;\n },\n\n /**\n * Starts a `childApp`\n *\n * @private\n * @method _startChildApp\n */\n _startChildApp(childApp, options) {\n const opts = this._getChildStartOpts(childApp);\n return childApp.start(_.extend(opts, options));\n },\n\n /**\n * Handles explicit boolean values of restartWithParent\n * restartWithParent === false does nothing\n *\n * @private\n * @method _shouldStartWithRestart\n */\n _shouldActWithRestart(childApp, action) {\n if (!this._isRestarting) {return true;}\n const restartWithParent = _.result(childApp, 'restartWithParent');\n if (restartWithParent === true) {return true;}\n if (restartWithParent !== false && _.result(childApp, action)) {return true;}\n },\n\n /**\n * Starts `childApps` if allowed by child\n *\n * @private\n * @method _startChildApps\n */\n _startChildApps() {\n const action = 'startWithParent';\n _.each(this._childApps, childApp => {\n if (!this._shouldActWithRestart(childApp, action)) {return;}\n if (!this._isRestarting && !_.result(childApp, action)) {return;}\n this._startChildApp(childApp);\n });\n },\n\n /**\n * Stops `childApps` if allowed by child\n *\n * @private\n * @method _stopChildApps\n */\n _stopChildApps() {\n const action = 'stopWithParent';\n _.each(this._childApps, childApp => {\n if (!this._shouldActWithRestart(childApp, action)) {return;}\n if (!this._isRestarting && !_.result(childApp, action)) {return;}\n childApp.stop();\n });\n },\n\n /**\n * Starts `childApp`\n *\n * @param {String} appName - Name of childApp to start\n * @param {Object} options - Start options for app\n * @public\n * @method startChildApp\n */\n startChildApp(appName, options) {\n const childApp = this.getChildApp(appName);\n return this._startChildApp(childApp, options);\n },\n\n /**\n * Stops `childApp`\n *\n * @param {String} appName - Name of childApp to stop\n * @param {Object} options - Stop options for app\n * @public\n * @method stopChildApp\n */\n stopChildApp(appName, options) {\n return this.getChildApp(appName).stop(options);\n },\n\n /**\n * Destroys `childApps` if allowed by child\n *\n * @private\n * @method _destroyChildApps\n */\n _destroyChildApps() {\n _.each(this._childApps, function(childApp) {\n if (!_.result(childApp, 'preventDestroy')) {\n childApp.destroy();\n }\n });\n },\n\n /**\n * Internal helper to instantiate and `App` from on `Object`\n *\n * @private\n * @method _buildAppFromObject\n * @param {Object} appConfig - `AppClass` and any other option for the `App`\n * @returns {App}\n */\n _buildAppFromObject(appConfig) {\n const AppClass = appConfig.AppClass;\n const options = _.omit(appConfig, 'AppClass', 'regionName', 'getOptions');\n\n const app = this.buildApp(AppClass, options);\n\n app._tkOpts = _.pick(appConfig, 'regionName', 'getOptions');\n\n return app;\n },\n\n /**\n * Helper for building an App and return it\n *\n * @private\n * @method _buildApp\n * @param {App} AppClass - An App Class\n * @param {Object} AppClass - Optionally passed as an appConfig Object\n * @param {Object} [options] - options for the AppClass\n * @returns {App}\n */\n _buildApp(AppClass, options) {\n if (_.isFunction(AppClass)) {\n return this.buildApp(AppClass, options);\n }\n if (_.isObject(AppClass)) {\n return this._buildAppFromObject(AppClass);\n }\n },\n\n /**\n * Build an App and return it\n * Override for dynamic App building\n *\n * @public\n * @method buildApp\n * @param {App} [AppClass] - An App Class\n * @param {Object} [options] - options for the AppClass\n * @returns {App}\n */\n buildApp(AppClass, options) {\n // options on childApp definition supersede childAppOptions\n options = _.extend({}, this.childAppOptions, options);\n\n return new AppClass(options);\n },\n\n /**\n * Internal helper to verify `appName` is unique and not in use\n *\n * @private\n * @method _ensureAppIsUnique\n * @param {String} appName - Name of app to test\n * @throws DuplicateChildAppError - Thrown if `App` already has an `appName` registered\n */\n _ensureAppIsUnique(appName) {\n if (this._childApps[appName]) {\n throw new Error(`A child App with name \"${ appName }\" has already been added.`);\n }\n },\n\n /**\n * Add child `App`s to this `App`\n *\n * @public\n * @method addChildApps\n * @param {Object} childApps - Hash of names and `AppClass` or `appConfig`\n */\n addChildApps(childApps) {\n _.each(childApps, _.bind(function(childApp, appName) {\n this.addChildApp(appName, childApp);\n }, this));\n },\n\n /**\n * Build's childApp and registers it with this App\n * Starts the childApp, if this app is running and child is `startWithParent`\n *\n * @public\n * @method addChildApp\n * @param {String} appName - Name of App to register\n * @param {App} AppClass - An App Class\n * @param {Object} AppClass - Optionally passed as an appConfig Object\n * @param {Object} [options] - options for the AppClass\n * @throws AddChildAppError - Thrown if no childApp could be built from params\n * @returns {App}\n */\n addChildApp(appName, AppClass, options) {\n this._ensureAppIsUnique(appName);\n\n const childApp = this._buildApp(AppClass, options);\n\n if (!childApp) {\n throw new Error('App build failed. Incorrect configuration.');\n }\n\n childApp._name = appName;\n\n this._childApps[appName] = childApp;\n\n // When the app is destroyed remove the cached app.\n // Listener setup relative to the childApp's running state (using _on)\n childApp._on('destroy', _.partial(this._removeChildApp, appName), this);\n\n if (this.isRunning() && _.result(childApp, 'startWithParent')) {\n this._startChildApp(childApp);\n }\n\n return childApp;\n },\n\n /**\n * Returns registered child `App`s name\n *\n * @public\n * @method getName\n * @returns {String}\n */\n getName() {\n return this._name;\n },\n\n\n /**\n * Returns registered child `App`s array\n *\n * @public\n * @method getChildApps\n * @returns {Array}\n */\n getChildApps() {\n return _.clone(this._childApps);\n },\n\n /**\n * Returns registered child `App`\n *\n * @public\n * @method getChildApp\n * @param {String} appName - Name of App to retrieve\n * @returns {App}\n */\n getChildApp(appName) {\n return this._childApps[appName];\n },\n\n /**\n * Internal helper. Unregisters child `App`\n *\n * @private\n * @method _removeChildApp\n * @param {String} appName - Name of App to unregister\n * @returns {App}\n */\n _removeChildApp(appName) {\n delete this._childApps[appName]._name;\n delete this._childApps[appName];\n },\n\n /**\n * Removes all childApps and returns them.\n * The return is useful if any app is using `preventDestroy`\n *\n * @public\n * @method removeChildApps\n * @returns {Array}\n */\n removeChildApps() {\n const childApps = this.getChildApps();\n\n _.each(this._childApps, _.bind(function(childApp, appName) {\n this.removeChildApp(appName);\n }, this));\n\n return childApps;\n },\n\n /**\n * Destroys or removes registered child `App` by name\n * depending on `preventDestroy`\n *\n * @public\n * @method removeChildApp\n * @param {String} appName - Name of App to destroy\n * @param {Object} [options.preventDestroy] - Flag to remove but prevent App destroy\n * @returns {App}\n */\n removeChildApp(appName, options) {\n options = _.extend({}, options);\n\n const childApp = this.getChildApp(appName);\n\n if (!childApp) {\n return;\n }\n\n // if preventDestroy simply unregister the child app\n if (options.preventDestroy || _.result(childApp, 'preventDestroy')) {\n this._removeChildApp(appName);\n } else {\n childApp.destroy();\n }\n\n return childApp;\n }\n};\n","import _ from 'underscore';\nimport { MnObject } from 'backbone.marionette';\n\n/**\n * This provides methods used for registering events while App is running and cleans them up at `onStop`. It's not meant to\n * be used directly.\n *\n * @mixin\n */\n\nexport default {\n /**\n * Internal method to stop any registered events.\n *\n * @private\n * @method _stopRunningEvents\n */\n _stopRunningEvents() {\n _.each(this._runningEvents, _.bind(function(args) {\n this.off.apply(this, args);\n }, this));\n this._runningEvents = [];\n },\n\n /**\n * Internal method to stop any registered listeners.\n *\n * @private\n * @method _stopRunningListeners\n */\n _stopRunningListeners() {\n _.each(this._runningListeningTo, _.bind(function(args) {\n this.stopListening.apply(this, args);\n }, this));\n this._runningListeningTo = [];\n },\n\n /**\n * Overrides `Backbone.Event.on()`\n * If this `App` is running it will register the event for removal `onStop`\n *\n * @public\n * @method on\n * @returns {EventListeners}\n */\n on() {\n if (this._isRunning) {\n this._runningEvents = (this._runningEvents || []);\n this._runningEvents.push(arguments);\n }\n\n return MnObject.prototype.on.apply(this, arguments);\n },\n\n /**\n * Keep a copy of non-running on for internal use\n *\n * @private\n * @method _on\n * @returns {EventListeners}\n */\n _on: MnObject.prototype.on,\n\n /**\n * Overrides `Backbone.Event.listenTo()`\n * If this `App` is running it will register the listener for removal `onStop`\n *\n * @public\n * @method listenTo\n * @returns {EventListeners}\n */\n listenTo() {\n if (this._isRunning) {\n this._runningListeningTo = (this._runningListeningTo || []);\n this._runningListeningTo.push(arguments);\n }\n return MnObject.prototype.listenTo.apply(this, arguments);\n },\n\n /**\n * Keep a copy of non-running on for internal use\n *\n * @private\n * @method _listenTo\n * @returns {EventListeners}\n */\n _listenTo: MnObject.prototype.listenTo,\n\n /**\n * Overrides `Backbone.Event.listenToOnce()`\n * If this `App` is running it will register the listener for removal `onStop`\n *\n * @public\n * @method listenToOnce\n * @returns {EventListeners}\n */\n listenToOnce() {\n if (this._isRunning) {\n this._runningListeningTo = (this._runningListeningTo || []);\n this._runningListeningTo.push(arguments);\n }\n\n return MnObject.prototype.listenToOnce.apply(this, arguments);\n }\n};\n","import _ from 'underscore';\n\nexport default {\n /**\n * Used as the prefix for events forwarded from\n * the component's view to the component\n * @type {String}\n * @default false\n */\n viewEventPrefix: false,\n\n /**\n * Constructs hashes and options for view event proxy\n *\n * @private\n * @method _buildEventProxies\n */\n _buildEventProxies() {\n const viewEvents = _.result(this, 'viewEvents') || {};\n this._viewEvents = this.normalizeMethods(viewEvents);\n this._viewTriggers = _.result(this, 'viewTriggers') || {};\n this._viewEventPrefix = _.result(this, 'viewEventPrefix');\n },\n\n /**\n * Proxies the ViewClass's viewEvents to the Component itself\n * Similar to CollectionView childEvents\n * (http://marionettejs.com/docs/v2.3.2/marionette.collectionview.html#collectionviews-childevents)\n *\n * @private\n * @method _proxyViewEvents\n * @param {Mn.View|Mn.CollectionView} view -\n * The instantiated ViewClass.\n */\n _proxyViewEvents(view) {\n this.listenTo(view, 'all', this._childViewEventHandler);\n },\n\n /**\n * Event handler for view proxy\n * Similar to CollectionView childEvents\n * (http://marionettejs.com/docs/v2.3.2/marionette.collectionview.html#collectionviews-childevents)\n *\n * @private\n * @method _childViewEventHandler\n * @param {String} - event name\n */\n _childViewEventHandler(eventName, ...args) {\n const viewEvents = this._viewEvents;\n\n if (_.isFunction(viewEvents[eventName])) {\n viewEvents[eventName].apply(this, args);\n }\n\n // use the parent view's proxyEvent handlers\n const viewTriggers = this._viewTriggers;\n\n // Call the event with the proxy name on the parent layout\n if (_.isString(viewTriggers[eventName])) {\n this.triggerMethod(viewTriggers[eventName], ...args);\n }\n\n const prefix = this._viewEventPrefix;\n\n if (prefix !== false) {\n const viewEventName = `${ prefix }:${ eventName }`;\n\n this.triggerMethod(viewEventName, ...args);\n }\n }\n};\n","import _ from 'underscore';\nimport { Application } from 'backbone.marionette';\nimport StateMixin from './mixins/state';\nimport ChildAppsMixin from './mixins/child-apps';\nimport EventListenersMixin from './mixins/event-listeners';\nimport ViewEventsMixin from './mixins/view-events';\n\nconst ClassOptions = [\n 'startWithParent',\n 'restartWithParent',\n 'stopWithParent',\n 'startAfterInitialized',\n 'preventDestroy',\n 'StateModel',\n 'stateEvents',\n 'viewEventPrefix',\n 'viewEvents',\n 'viewTriggers'\n];\n\n/**\n * Marionette.Application with an `initialize` / `start` / `stop` / `destroy` lifecycle.\n *\n * @public\n * @class App\n * @memberOf Toolkit\n * @memberOf Marionette\n */\nconst App = Application.extend({\n\n /**\n * Internal flag indiciate when `App` has started but has not yet stopped.\n *\n * @private\n * @type {Boolean}\n * @default false\n */\n _isRunning: false,\n\n /**\n * Internal flag indiciate when `App` is in the process of stopping then starting.\n *\n * @private\n * @type {Boolean}\n * @default false\n */\n _isRestarting: false,\n\n /**\n * Set to true if a parent `App` should not be able to destroy this `App`.\n *\n * @type {Boolean|Function}\n * @default false\n */\n preventDestroy: false,\n\n /**\n * Set to true if `App` should be started after it is initialized.\n *\n * @type {Boolean|Function}\n * @default false\n */\n startAfterInitialized: false,\n\n /**\n * Set to true if `App` should be started after its parent starts.\n *\n * @type {Boolean|Function}\n * @default false\n */\n startWithParent: false,\n\n /**\n * Set to false if `App` should not stop after its parent stops.\n *\n * @type {Boolean|Function}\n * @default true\n */\n stopWithParent: true,\n\n\n /**\n * Set this to determine if a parent `App` should maintain the child's\n * lifecycle during a restart.\n *\n * @type {Boolean|Function}\n * @default null\n */\n restartWithParent: null,\n\n /**\n * @public\n * @constructs App\n * @param {Object} [options] - Settings for the App.\n * @param {Boolean} [options.startWithParent]\n * @param {Boolean} [options.restartWithParent]\n * @param {Boolean} [options.stopWithParent]\n * @param {Boolean} [options.startAfterInitialized]\n * @param {Boolean} [options.preventDestroy]\n * @param {Object} [options.state] - Attributes to set on the state model.\n */\n constructor(options = {}) {\n this.mergeOptions(options, ClassOptions);\n\n this.options = _.extend({}, _.result(this, 'options'), options);\n\n // ChildAppsMixin\n this._initChildApps(options);\n\n Application.call(this, options);\n\n if (_.result(this, 'startAfterInitialized')) {\n this.start(options);\n }\n },\n\n /**\n * Internal helper to verify if `App` has been destroyed\n *\n * @private\n * @method _ensureAppIsIntact\n * @memberOf App\n * @throws AppDestroyedError - Thrown if `App` has already been destroyed\n */\n _ensureAppIsIntact() {\n if (this._isDestroyed) {\n throw new Error('App has already been destroyed and cannot be used.');\n }\n },\n\n /**\n * Gets the value of internal `_isRunning` flag\n *\n * @public\n * @method isRunning\n * @memberOf App\n * @returns {Boolean}\n */\n isRunning() {\n return this._isRunning;\n },\n\n /**\n * Gets the value of internal `_isRestarting` flag\n *\n * @public\n * @method isRestarting\n * @memberOf App\n * @returns {Boolean}\n */\n isRestarting() {\n return this._isRestarting;\n },\n\n /**\n * Sets the app lifecycle to running.\n *\n * @public\n * @method start\n * @memberOf App\n * @param {Object} [options] - Settings for the App passed through to events\n * @event App#before:start - passes options\n * @returns {App}\n */\n start(options = {}) {\n this._ensureAppIsIntact();\n\n if (this._isRunning) {\n return this;\n }\n\n if (options.region) {\n this.setRegion(options.region);\n }\n\n if (options.view) {\n this.setView(options.view);\n }\n\n // StateMixin\n this._initState(options);\n\n // ViewEventMixin\n this._buildEventProxies();\n\n this.triggerMethod('before:start', options);\n\n this._isRunning = true;\n\n this._bindRunningEvents();\n\n this.triggerStart(options);\n\n return this;\n },\n\n /**\n * Sets up region, view, and state events.\n * To only be called after `isRunning` is true\n *\n * @private\n * @method _bindRunningEvents\n * @memberOf App\n */\n _bindRunningEvents() {\n if (this._region) {\n this._regionEventMonitor();\n }\n\n if (this._view) {\n this._proxyViewEvents(this._view);\n }\n\n // StateMixin\n this.delegateStateEvents();\n },\n\n /**\n * Sets the app lifecycle to not running\n * then sets the app lifecycle to running with ending state\n *\n * @public\n * @method restart\n * @memberOf App\n * @returns {App}\n */\n restart() {\n const state = this.getState().attributes;\n\n this._isRestarting = true;\n this.stop().start({ state });\n this._isRestarting = false;\n\n return this;\n },\n\n /**\n * Starts children and triggers start event\n * For calling within `triggerStart`\n *\n * @public\n * @method finallyStart\n * @memberOf App\n * @event App#start - passes any arguments\n * @returns\n */\n finallyStart() {\n this._startChildApps();\n this.triggerMethod('start', ...arguments);\n },\n\n /**\n * Triggers start event via finallyStart.\n * Override to introduce async start\n *\n * @public\n * @method triggerStart\n * @memberOf App\n * @param {Object} [options] - Settings for the App passed through to events\n * @returns\n */\n triggerStart(options) {\n this.finallyStart(options);\n },\n\n /**\n * Sets the app lifecycle to not running.\n * Removes any listeners added during the running state\n *\n * @public\n * @method stop\n * @memberOf App\n * @param {Object} [options] - Settings for the App passed through to events\n * @event App#before:stop - passes options\n * @event App#stop - passes options\n * @returns {App}\n */\n stop(options) {\n if (!this._isRunning) {\n return this;\n }\n\n this.triggerMethod('before:stop', options);\n\n this._stopChildApps();\n\n this._isRunning = false;\n\n this.triggerMethod('stop', options);\n\n // Running events are cleaned up after stop so that\n // `stop` event handlers still fire\n this._stopRunningListeners();\n this._stopRunningEvents();\n\n return this;\n },\n\n /**\n * Stops the `App` and sets it destroyed.\n *\n * @public\n * @method destroy\n * @memberOf App\n */\n destroy() {\n if (this._isDestroyed) {\n return this;\n }\n\n this.stop();\n\n this._removeView();\n\n this._destroyChildApps();\n\n Application.prototype.destroy.apply(this, arguments);\n\n return this;\n },\n\n /**\n * Set the Application's Region\n *\n * @public\n * @method setRegion\n * @memberOf App\n * @param {Region} [region] - Region to use with the app\n * @returns {Region}\n */\n setRegion(region) {\n if (this._region) {\n this.stopListening(this._region);\n }\n\n this._region = region;\n\n if (region.currentView) {\n this.setView(region.currentView);\n }\n\n if (this._isRunning) {\n this._regionEventMonitor();\n }\n\n return region;\n },\n\n /**\n * Monitors the apps region before:show event so the region's view\n * is available to the app\n *\n * @private\n * @method _regionEventMonitor\n * @memberOf App\n */\n _regionEventMonitor() {\n this.listenTo(this._region, {\n 'before:show': this._onBeforeShow,\n 'empty': this._onEmpty\n });\n },\n\n /**\n * Region monitor handler which sets the app's view to the region's view\n *\n * @private\n * @method _onBeforeShow\n * @memberOf App\n */\n _onBeforeShow(region, view) {\n this.setView(view);\n },\n\n /**\n * Region monitor handler which empties the region's view\n *\n * @private\n * @method _onEmpty\n * @memberOf App\n */\n _onEmpty(region, view) {\n if (view !== this._view) {return;}\n\n this._removeView();\n },\n\n /**\n * Region monitor handler which deletes the region's view and listeners to view\n *\n * @private\n * @method _removeView\n * @memberOf App\n */\n _removeView() {\n if (this._view) {\n this.stopListening(this._view);\n delete this._view;\n }\n },\n\n /**\n * Get the Application's Region or\n * Get a region from the Application's View\n *\n * @public\n * @method getRegion\n * @memberOf App\n * @param {String} [regionName] - Optional regionName to get from the view\n * @returns {Region}\n */\n getRegion(regionName) {\n if (!regionName) {\n return this._region;\n }\n\n return this.getView().getRegion(regionName);\n },\n\n /**\n * Set the Application's View\n *\n * @public\n * @method setView\n * @memberOf App\n * @param {View} [view] - View to use with the app\n * @returns {View}\n */\n setView(view) {\n if (this._view === view) {\n return view;\n }\n\n if (this._view) {\n this.stopListening(this._view);\n }\n\n this._view = view;\n\n // ViewEventsMixin\n if (this._isRunning) {\n this._proxyViewEvents(view);\n }\n\n // Internal non-running listener\n this._listenTo(this._view, 'destroy', this._removeView);\n\n return view;\n },\n\n /**\n * Get the Application's View\n *\n * @public\n * @method getView\n * @memberOf App\n * @returns {View}\n */\n getView() {\n return this._view || this._region && this._region.currentView;\n },\n\n /**\n * Shows a view in the Application's region\n *\n * @public\n * @method showView\n * @param {View} view - Child view instance defaults to App's view\n * @param {...args} Additional args that get passed along\n * @returns {View}\n */\n showView(view = this._view, ...args) {\n const region = this.getRegion();\n\n region.show(view, ...args);\n\n if (!this.isRunning()) {this.setView(region.currentView);}\n\n return view;\n },\n\n /**\n * Shows a view in the region of the app's view\n *\n * @public\n * @method showChildView\n * @param {String} regionName - Name of region to show in\n * @param {View} view - Child view instance\n * @param {...args} Additional args that get passed along\n * @returns {View} - Child view instance\n */\n showChildView(regionName, view, ...args) {\n this.getView().showChildView(regionName, view, ...args);\n\n return view;\n },\n\n /**\n * Returns view from the App view by region name.\n *\n * @public\n * @method getChildView\n * @param {String} regionName - Name of region to get view from\n * @returns {View}\n */\n getChildView(regionName) {\n return this.getView().getChildView(regionName);\n }\n});\n\n_.extend(App.prototype, StateMixin, ChildAppsMixin, EventListenersMixin, ViewEventsMixin);\n\nexport default App;\n","import _ from 'underscore';\nimport Backbone from 'backbone';\nimport { Application, View } from 'backbone.marionette';\nimport StateMixin from './mixins/state';\nimport ViewEventsMixin from './mixins/view-events';\n\nconst ClassOptions = [\n 'regionOptions',\n 'ViewClass',\n 'viewEventPrefix',\n 'viewEvents',\n 'viewTriggers',\n 'viewOptions'\n];\n\n/**\n * Reusable Marionette.MnObject with View management boilerplate\n *\n * @public\n * @class Component\n * @memberOf Toolkit\n * @memberOf Marionette\n */\nconst Component = Application.extend({\n\n /**\n * The view class to be managed.\n * @type {Mn.View|Mn.CollectionView}\n * @default Marionette.View\n */\n ViewClass: View,\n\n /**\n * @public\n * @constructs Component\n * @param {Object} [options] - Settings for the component.\n * @param {Object} [options.state] - Attributes to set on the state model.\n * @param {Mn.View|Mn.CollectionView} [options.ViewClass]\n * - The view class to be managed.\n * @param {String} [options.viewEventPrefix]\n * - Used as the prefix for events forwarded from the component's view to the component\n * @param {Object} [options.viewOptions] - Options hash passed to an instantiated ViewClass.\n * @param {Marionette.Region} [options.region] - The region to show the component in.\n */\n constructor(options = {}) {\n // Make defaults available to this\n this.mergeOptions(options, ClassOptions);\n\n this.options = _.extend({}, _.result(this, 'options'), options);\n\n // ViewEventMixin\n this._buildEventProxies();\n\n // StateMixin\n this._initState(options);\n\n Application.call(this, options);\n\n // StateMixin\n this.delegateStateEvents();\n },\n\n /**\n * Set the Component's region and then show it.\n *\n * @public\n * @method showIn\n * @memberOf Component\n * @param {Marionette.Region} region - The region for the component\n * @param {Object} [viewOptions] - Options hash mixed into the instantiated ViewClass.\n * @param {Object} [regionOptions] - Options hash mixed into the instantiated region.\n * @returns {Component}\n */\n showIn(region, viewOptions, regionOptions) {\n this._region = region;\n\n this.show(viewOptions, regionOptions);\n\n return this;\n },\n\n /**\n * Show the Component in its region.\n *\n * @public\n * @event Component#before:show\n * @event Component#show\n * @throws ComponentRegionError - Thrown if component has no defined region.\n * @method show\n * @param {Object} [viewOptions] - Options hash mixed into the instantiated ViewClass.\n * @param {Object} [regionOptions] - Options hash passed to the region on show.\n * @memberOf Component\n * @returns {Component}\n */\n show(viewOptions, regionOptions) {\n const region = this.getRegion();\n\n if (!region) {\n throw new Error('Component has no defined region.');\n }\n\n const view = this._getView(viewOptions);\n\n this.stopListening(region.currentView, 'destroy', this.destroy);\n\n this.triggerMethod('before:show', this, view, viewOptions, regionOptions);\n\n this.showView(view, this.mixinRegionOptions(regionOptions));\n\n this.listenTo(region.currentView, 'destroy', this.destroy);\n\n this.triggerMethod('show', this, view, viewOptions, regionOptions);\n\n return this;\n },\n\n /**\n * Empty the Components region without destroying it\n *\n * @public\n * @throws ComponentRegionError - Thrown if component has no defined region.\n * @method empty\n * @memberOf Component\n * @returns {Component}\n */\n empty() {\n const region = this.getRegion();\n\n if (!region) {\n throw new Error('Component has no defined region.');\n }\n\n this.stopListening(region.currentView, 'destroy', this.destroy);\n\n region.empty();\n\n return this;\n },\n\n /**\n * Mixin regionOptions\n *\n * @public\n * @abstract\n * @method mixinRegionOptions\n * @memberOf Component\n * @param {Object} [options] - Additional options to mixin\n * @returns {Object}\n */\n mixinRegionOptions(options) {\n const regionOptions = _.result(this, 'regionOptions');\n\n return _.extend({}, regionOptions, options);\n },\n\n /**\n * Get the Component view instance.\n *\n * @private\n * @method _getView\n * @memberOf Component\n * @param {Object} [options] - Options that can be used to determine the ViewClass.\n * @returns {View}\n */\n _getView(options) {\n const ViewClass = this._getViewClass(options);\n\n const viewOptions = this.mixinViewOptions(options);\n\n const view = this.buildView(ViewClass, viewOptions);\n\n // ViewEventMixin\n this._proxyViewEvents(view);\n\n return view;\n },\n\n /**\n * Get the Component ViewClass class.\n * Checks if the `ViewClass` is a view class (the common case)\n * Then check if it's a function (which we assume that returns a view class)\n *\n * @private\n * @method _getViewClass\n * @memberOf Component\n * @param {Object} [options] - Options that can be used to determine the ViewClass.\n * @returns {View}\n */\n _getViewClass(options = {}) {\n const ViewClass = this.ViewClass;\n\n if (ViewClass.prototype instanceof Backbone.View || ViewClass === Backbone.View) {\n return ViewClass;\n } else if (_.isFunction(ViewClass)) {\n return ViewClass.call(this, options);\n }\n\n throw new Error('\"ViewClass\" must be a view class or a function that returns a view class');\n },\n\n /**\n * Mixin initial State with any other viewOptions\n *\n * @public\n * @abstract\n * @method mixinViewOptions\n * @memberOf Component\n * @param {Object} [options] - Additional options to mixin\n * @returns {Object}\n */\n mixinViewOptions(options) {\n const viewOptions = _.result(this, 'viewOptions');\n\n return _.extend({ state: this.getState().attributes }, viewOptions, options);\n },\n\n /**\n * Builds the view class with options\n * If you need a dynamic ViewClass override this function\n *\n * @public\n * @abstract\n * @method buildView\n * @memberOf Component\n * @param {Mn.View|Mn.CollectionView} ViewClass -\n * The view class to instantiate.\n * @param {Object} [viewOptions] - Options to pass to the View\n * @returns {Mn.View|Mn.CollectionView}\n */\n buildView(ViewClass, viewOptions) {\n return new ViewClass(viewOptions);\n },\n\n /**\n * Empty the region and destroy the component.\n *\n * @public\n * @method destroy\n * @param {Object} [options] - Options passed to Mn.Application `destroy`\n * @memberOf Component\n */\n destroy() {\n if (this._isDestroyed) {\n return this;\n }\n\n const region = this.getRegion();\n if (region) {region.empty();}\n\n Application.prototype.destroy.apply(this, arguments);\n\n return this;\n }\n}, {\n /**\n * Sets the region for a Component Class\n *\n * @public\n * @method setRegion\n * @param {Marionette.Region} - region definition for instantiated components\n * @memberOf Component.prototype\n */\n setRegion(region) {\n this.prototype.region = region;\n }\n});\n\n_.extend(Component.prototype, StateMixin, ViewEventsMixin);\n\nexport default Component;\n","import _ from 'underscore';\n\nimport StateMixin from './mixins/state';\nimport App from './app';\nimport Component from './component';\n\nimport { version as VERSION } from '../package.json';\n\n/**\n * @module Toolkit\n */\n\nfunction mixinState(classDefinition) {\n let _StateMixin = StateMixin;\n\n if (classDefinition.prototype.StateModel) {\n _StateMixin = _.omit(StateMixin, 'StateModel');\n }\n\n _.extend(classDefinition.prototype, _StateMixin);\n}\n\nexport {\n App,\n Component,\n mixinState,\n StateMixin,\n VERSION\n};\n"],"names":["ClassOptions","StateModel","Backbone","Model","initState","options","_initState","delegateStateEvents","this","mergeOptions","_removeEventHandlers","_getStateModel","_stateModel","state","_setEventHandlers","undelegateStateEvents","bindEvents","_","result","unbindEvents","on","_destroyState","stopListening","off","prototype","isFunction","call","Error","setState","set","apply","arguments","resetStateDefaults","defaults","getState","attr","get","toggleState","val","length","hasState","has","_initChildApps","_childApps","childApps","addChildApps","_getChildStartOpts","childApp","tkOpts","_tkOpts","opts","region","getRegion","regionName","each","getOptions","opt","_this","getOption","_startChildApp","start","extend","_shouldActWithRestart","action","_isRestarting","restartWithParent","_startChildApps","_this2","_stopChildApps","_this3","stop","startChildApp","appName","getChildApp","stopChildApp","_destroyChildApps","destroy","_buildAppFromObject","appConfig","AppClass","omit","app","buildApp","pick","_buildApp","isObject","childAppOptions","_ensureAppIsUnique","bind","addChildApp","_name","_on","partial","_removeChildApp","isRunning","getName","getChildApps","clone","removeChildApps","removeChildApp","preventDestroy","_stopRunningEvents","_runningEvents","args","_stopRunningListeners","_runningListeningTo","_isRunning","push","MnObject","listenTo","_listenTo","listenToOnce","viewEventPrefix","_buildEventProxies","viewEvents","_viewEvents","normalizeMethods","_viewTriggers","_viewEventPrefix","_proxyViewEvents","view","_childViewEventHandler","eventName","viewTriggers","isString","triggerMethod","prefix","viewEventName","App","Application","startAfterInitialized","startWithParent","stopWithParent","constructor","_ensureAppIsIntact","_isDestroyed","isRestarting","setRegion","setView","_bindRunningEvents","triggerStart","_region","_regionEventMonitor","_view","restart","attributes","finallyStart","_removeView","currentView","_onBeforeShow","_onEmpty","getView","showView","show","showChildView","getChildView","StateMixin","ChildAppsMixin","EventListenersMixin","ViewEventsMixin","Component","ViewClass","View","showIn","viewOptions","regionOptions","_getView","mixinRegionOptions","empty","_getViewClass","mixinViewOptions","buildView","classDefinition","_StateMixin"],"mappings":";;;;;;ygBAGA,IAAMA,EAAe,CACnB,aACA,iBASa,CAObC,WAAYC,EAASC,MASrBC,yBAAUC,yDAAU,eACbC,WAAWD,QACXE,sBAEEC,MAQTF,oBAAWD,QAEJI,aAAaJ,EAASL,QAGtBU,2BAECT,EAAaO,KAAKG,eAAeN,QAElCO,YAAc,IAAIX,EAAWI,EAAQQ,YAErCC,qBASPP,2CACOQ,6BACAC,WAAWR,KAAKI,YAAaK,EAAEC,OAAOV,KAAM,gBAE1CA,MASTO,6CACOI,aAAaX,KAAKI,aAEhBJ,MASTM,kCACOM,GAAG,UAAWZ,KAAKa,gBAS1BX,gCACOF,KAAKI,mBAELG,6BACAH,YAAYU,qBACZC,IAAI,UAAWf,KAAKa,iBAc3BV,wBAAeN,MACTG,KAAKP,WAAWuB,qBAAqBtB,EAASC,OAASK,KAAKP,aAAeC,EAASC,aAC/EK,KAAKP,WACP,GAAIgB,EAAEQ,WAAWjB,KAAKP,mBACpBO,KAAKP,WAAWyB,KAAKlB,KAAMH,SAG9B,IAAIsB,MAAM,gFAalBC,2BACSpB,KAAKI,YAAYiB,IAAIC,MAAMtB,KAAKI,YAAamB,YAYtDC,kCACQC,EAAWhB,EAAEC,OAAOV,KAAKI,YAAa,mBAErCJ,KAAKI,YAAYiB,IAAII,IAW9BC,kBAASC,UACFA,EAIE3B,KAAKI,YAAYwB,IAAIN,MAAMtB,KAAKI,YAAamB,WAH3CvB,KAAKI,aAehByB,qBAAYF,EAAMG,UACZP,UAAUQ,OAAS,EAAW/B,KAAKI,YAAYiB,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AmBlK,OACXgK,EAAgBpJ,EAAEC,OAAOV,KAAM,wBAE9BS,EAAE4C,OAAO,GAAIwG,EAAehK,IAYrCiK,kBAASjK,OACD4J,EAAYzJ,KAAKiK,cAAcpK,GAE/B+J,EAAc5J,KAAKkK,iBAAiBrK,GAEpCmH,EAAOhH,KAAKmK,UAAUV,EAAWG,eAGlC7C,iBAAiBC,GAEfA,GAcTiD,6BAAcpK,yDAAU,GAChB4J,EAAYzJ,KAAKyJ,aAEnBA,EAAUzI,qBAAqBtB,EAASgK,MAAQD,IAAc/J,EAASgK,YAClED,EACF,GAAIhJ,EAAEQ,WAAWwI,UACfA,EAAUvI,KAAKlB,KAAMH,SAGxB,IAAIsB,MAAM,6EAalB+I,0BAAiBrK,OACT+J,EAAcnJ,EAAEC,OAAOV,KAAM,sBAE5BS,EAAE4C,OAAO,CAAEhD,MAAOL,KAAK0B,WAAW+G,YAAcmB,EAAa/J,IAgBtEsK,mBAAUV,EAAWG,UACZ,IAAIH,EAAUG,IAWvBxF,sBACMpE,KAAK+H,oBACA/H,SAGH2C,EAAS3C,KAAK4C,mBAChBD,GAASA,EAAOqH,QAEpBvC,cAAYzG,UAAUoD,QAAQ9C,MAAMtB,KAAMuB,WAEnCvB,OAER,CASDiI,mBAAUtF,QACH3B,UAAU2B,OAASA,KAI5BlC,EAAE4C,OAAOmG,EAAUxI,UAAWoI,EAAYG,uEC/P1C,SAAoBa,OACdC,EAAcjB,EAEdgB,EAAgBpJ,UAAUvB,aAC5B4K,EAAc5J,EAAE+D,KAAK4E,EAAY,eAGnC3I,EAAE4C,OAAO+G,EAAgBpJ,UAAWqJ"} \ No newline at end of file diff --git a/package.json b/package.json index 6c1bf7c..f005b7b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "marionette.toolkit", - "version": "6.0.1", + "version": "6.1.0", "description": "A collection of opinionated Backbone.Marionette extensions for large scale application architecture.", "main": "dist/marionette.toolkit.js", "module": "dist/marionette.toolkit.esm.js",