Skip to content

Commit

Permalink
Apply regionName and getOptions API to every childapp start
Browse files Browse the repository at this point in the history
Only a direct start was handled
  • Loading branch information
paulfalgout committed Aug 7, 2018
1 parent 7a428d3 commit 0d6e159
Showing 1 changed file with 33 additions and 45 deletions.
78 changes: 33 additions & 45 deletions src/mixins/child-apps.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@ export default {
}
},

/**
* Finds `regionName` and `getOptions` for the childApp
*
* @private
* @method _getChildStartOpts
*/
_getChildStartOpts(childApp) {
const tkOpts = childApp._tkOpts || {};

Expand All @@ -63,51 +69,43 @@ export default {
},

/**
* Starts a `childApp` if allowed by child
* Starts a `childApp`
*
* @private
* @method _startChildApp
*/
_startChildApp(childApp) {
if(_.result(childApp, 'startWithParent')) {
childApp.start();
}
_startChildApp(childApp, options) {
const opts = this._getChildStartOpts(childApp);
return childApp.start(_.extend(opts, options));
},

/**
* Starts `childApps` if allowed by child
* Handles explicit boolean values of restartWithParent
* restartWithParent === false does nothing
*
* @private
* @method _startChildApps
* @method _shouldStartWithRestart
*/
_startChildApps() {
if(!this._isRestarting) {
_.each(this._childApps, this._startChildApp);
return;
}

// Handles explicit boolean values of restartWithParent
// restartWithParent === false does nothing
_.each(this._childApps, childApp => {
const restartWithParent = _.result(childApp, 'restartWithParent');
if(restartWithParent === true) {
childApp.start();
return;
}
if(restartWithParent !== false) this._startChildApp(childApp);
});
_shouldActWithRestart(childApp, action) {
if(!this._isRestarting) return true;
const restartWithParent = _.result(childApp, 'restartWithParent');
if(restartWithParent === true) return true;
if(restartWithParent !== false && _.result(childApp, action)) return true;
},

/**
* Stops a `childApp` if allowed by child
* Starts `childApps` if allowed by child
*
* @private
* @method _stopChildApp
* @method _startChildApps
*/
_stopChildApp(childApp) {
if(_.result(childApp, 'stopWithParent')) {
childApp.stop();
}
_startChildApps() {
const action = 'startWithParent';
_.each(this._childApps, childApp => {
if(!this._shouldActWithRestart(childApp, action)) return;
if(!this._isRestarting && !_.result(childApp, action)) return;
this._startChildApp(childApp);
});
},

/**
Expand All @@ -117,20 +115,11 @@ export default {
* @method _stopChildApps
*/
_stopChildApps() {
if(!this._isRestarting) {
_.each(this._childApps, this._stopChildApp);
return;
}

// Handles explicit boolean values of restartWithParent
// restartWithParent === false does nothing
const action = 'stopWithParent';
_.each(this._childApps, childApp => {
const restartWithParent = _.result(childApp, 'restartWithParent');
if(restartWithParent === true) {
childApp.stop();
return;
}
if(restartWithParent !== false) this._stopChildApp(childApp);
if(!this._shouldActWithRestart(childApp, action)) return;
if(!this._isRestarting && !_.result(childApp, action)) return;
childApp.stop();
});
},

Expand All @@ -144,8 +133,7 @@ export default {
*/
startChildApp(appName, options) {
const childApp = this.getChildApp(appName);
const opts = this._getChildStartOpts(childApp);
return childApp.start(_.extend(opts, options));
return this._startChildApp(childApp, options);
},

/**
Expand Down Expand Up @@ -287,7 +275,7 @@ export default {
childApp._on('destroy', _.partial(this._removeChildApp, appName), this);

if(this.isRunning() && _.result(childApp, 'startWithParent')) {
childApp.start();
this._startChildApp(childApp);
}

return childApp;
Expand Down

0 comments on commit 0d6e159

Please sign in to comment.