[RN] Clarify, simplify the source code
This commit is contained in:
parent
99c2b60a1d
commit
51a1a7ed22
|
@ -2,25 +2,19 @@ import { ReducerRegistry } from '../base/redux';
|
|||
|
||||
import { APP_WILL_MOUNT, APP_WILL_UNMOUNT } from './actionTypes';
|
||||
|
||||
/**
|
||||
* The initial Redux state of features/app.
|
||||
*/
|
||||
const INITIAL_STATE = {
|
||||
/**
|
||||
* The one and only (i.e. singleton) App instance which is currently
|
||||
* mounted.
|
||||
*
|
||||
* @type {App}
|
||||
*/
|
||||
app: undefined
|
||||
};
|
||||
|
||||
ReducerRegistry.register('features/app', (state = INITIAL_STATE, action) => {
|
||||
ReducerRegistry.register('features/app', (state = {}, action) => {
|
||||
switch (action.type) {
|
||||
case APP_WILL_MOUNT:
|
||||
if (state.app !== action.app) {
|
||||
return {
|
||||
...state,
|
||||
|
||||
/**
|
||||
* The one and only (i.e. singleton) App instance which is
|
||||
* currently mounted.
|
||||
*
|
||||
* @type {App}
|
||||
*/
|
||||
app: action.app
|
||||
};
|
||||
}
|
||||
|
@ -30,7 +24,7 @@ ReducerRegistry.register('features/app', (state = INITIAL_STATE, action) => {
|
|||
if (state.app === action.app) {
|
||||
return {
|
||||
...state,
|
||||
app: INITIAL_STATE.app
|
||||
app: undefined
|
||||
};
|
||||
}
|
||||
break;
|
||||
|
|
|
@ -4,11 +4,11 @@ import { loadScript } from '../../base/util';
|
|||
* Loads config.js file from remote server.
|
||||
*
|
||||
* @param {string} host - Host where config.js is hosted.
|
||||
* @param {string} configLocation='/config.js' - Relative pah to config.js file.
|
||||
* @param {string} path='/config.js' - Relative pah to config.js file.
|
||||
* @returns {Promise<Object>}
|
||||
*/
|
||||
export function loadConfig(host, configLocation = '/config.js') {
|
||||
return loadScript(new URL(configLocation, host).toString())
|
||||
export function loadConfig(host, path = '/config.js') {
|
||||
return loadScript(new URL(path, host).toString())
|
||||
.then(() => {
|
||||
const config = window.config;
|
||||
|
||||
|
@ -21,11 +21,9 @@ export function loadConfig(host, configLocation = '/config.js') {
|
|||
|
||||
return config;
|
||||
})
|
||||
.catch(error => {
|
||||
console.error(
|
||||
`Failed to load ${configLocation} from ${host}`,
|
||||
error);
|
||||
.catch(err => {
|
||||
console.error(`Failed to load ${path} from ${host}`, err);
|
||||
|
||||
throw error;
|
||||
throw err;
|
||||
});
|
||||
}
|
||||
|
|
|
@ -59,15 +59,31 @@ ReducerRegistry.register(
|
|||
};
|
||||
|
||||
case SET_CONFIG:
|
||||
return {
|
||||
...state,
|
||||
config: {
|
||||
...action.config,
|
||||
...state.config
|
||||
}
|
||||
};
|
||||
return _setConfig(state, action);
|
||||
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* Reduces a specific Redux action SET_CONFIG of the feature
|
||||
* base/lib-jitsi-meet.
|
||||
*
|
||||
* @param {Object} state - The Redux state of the feature base/lib-jitsi-meet.
|
||||
* @param {Action} action - The Redux action SET_CONFIG to reduce.
|
||||
* @private
|
||||
* @returns {Object} The new state of the feature base/lib-jitsi-meet after the
|
||||
* reduction of the specified action.
|
||||
*/
|
||||
function _setConfig(state, action) {
|
||||
return {
|
||||
...state,
|
||||
config: {
|
||||
// The final config is the result of augmenting the default config
|
||||
// with whatever the deployment has chosen to override/overwrite.
|
||||
...INITIAL_STATE.config,
|
||||
...action.config
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue