2017-10-17 17:09:52 -05:00
|
|
|
// @flow
|
2017-07-06 13:39:59 -05:00
|
|
|
|
2018-07-11 11:42:43 +02:00
|
|
|
import { ReducerRegistry } from '../redux';
|
2016-10-05 09:36:59 -05:00
|
|
|
|
2017-06-09 14:09:23 -05:00
|
|
|
import { APP_WILL_MOUNT, APP_WILL_UNMOUNT } from './actionTypes';
|
2016-10-05 09:36:59 -05:00
|
|
|
|
2018-07-11 11:42:43 +02:00
|
|
|
ReducerRegistry.register('features/base/app', (state = {}, action) => {
|
2016-10-05 09:36:59 -05:00
|
|
|
switch (action.type) {
|
2017-06-09 14:09:23 -05:00
|
|
|
case APP_WILL_MOUNT: {
|
|
|
|
|
const { app } = action;
|
|
|
|
|
|
|
|
|
|
if (state.app !== app) {
|
2016-10-05 09:36:59 -05:00
|
|
|
return {
|
|
|
|
|
...state,
|
2016-12-07 16:08:35 -06:00
|
|
|
|
|
|
|
|
/**
|
2018-07-11 11:42:43 +02:00
|
|
|
* The one and only (i.e. singleton) {@link BaseApp} instance
|
|
|
|
|
* which is currently mounted.
|
2016-12-07 16:08:35 -06:00
|
|
|
*
|
2018-07-11 11:42:43 +02:00
|
|
|
* @type {BaseApp}
|
2016-12-07 16:08:35 -06:00
|
|
|
*/
|
2017-06-09 14:09:23 -05:00
|
|
|
app
|
2016-10-05 09:36:59 -05:00
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
break;
|
2017-06-09 14:09:23 -05:00
|
|
|
}
|
2016-10-05 09:36:59 -05:00
|
|
|
|
|
|
|
|
case APP_WILL_UNMOUNT:
|
|
|
|
|
if (state.app === action.app) {
|
|
|
|
|
return {
|
|
|
|
|
...state,
|
2016-12-07 16:08:35 -06:00
|
|
|
app: undefined
|
2016-10-05 09:36:59 -05:00
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return state;
|
|
|
|
|
});
|