[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';
|
import { APP_WILL_MOUNT, APP_WILL_UNMOUNT } from './actionTypes';
|
||||||
|
|
||||||
/**
|
ReducerRegistry.register('features/app', (state = {}, action) => {
|
||||||
* 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) => {
|
|
||||||
switch (action.type) {
|
switch (action.type) {
|
||||||
case APP_WILL_MOUNT:
|
case APP_WILL_MOUNT:
|
||||||
if (state.app !== action.app) {
|
if (state.app !== action.app) {
|
||||||
return {
|
return {
|
||||||
...state,
|
...state,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The one and only (i.e. singleton) App instance which is
|
||||||
|
* currently mounted.
|
||||||
|
*
|
||||||
|
* @type {App}
|
||||||
|
*/
|
||||||
app: action.app
|
app: action.app
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -30,7 +24,7 @@ ReducerRegistry.register('features/app', (state = INITIAL_STATE, action) => {
|
||||||
if (state.app === action.app) {
|
if (state.app === action.app) {
|
||||||
return {
|
return {
|
||||||
...state,
|
...state,
|
||||||
app: INITIAL_STATE.app
|
app: undefined
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -4,11 +4,11 @@ import { loadScript } from '../../base/util';
|
||||||
* Loads config.js file from remote server.
|
* Loads config.js file from remote server.
|
||||||
*
|
*
|
||||||
* @param {string} host - Host where config.js is hosted.
|
* @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>}
|
* @returns {Promise<Object>}
|
||||||
*/
|
*/
|
||||||
export function loadConfig(host, configLocation = '/config.js') {
|
export function loadConfig(host, path = '/config.js') {
|
||||||
return loadScript(new URL(configLocation, host).toString())
|
return loadScript(new URL(path, host).toString())
|
||||||
.then(() => {
|
.then(() => {
|
||||||
const config = window.config;
|
const config = window.config;
|
||||||
|
|
||||||
|
@ -21,11 +21,9 @@ export function loadConfig(host, configLocation = '/config.js') {
|
||||||
|
|
||||||
return config;
|
return config;
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch(err => {
|
||||||
console.error(
|
console.error(`Failed to load ${path} from ${host}`, err);
|
||||||
`Failed to load ${configLocation} from ${host}`,
|
|
||||||
error);
|
|
||||||
|
|
||||||
throw error;
|
throw err;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -59,15 +59,31 @@ ReducerRegistry.register(
|
||||||
};
|
};
|
||||||
|
|
||||||
case SET_CONFIG:
|
case SET_CONFIG:
|
||||||
return {
|
return _setConfig(state, action);
|
||||||
...state,
|
|
||||||
config: {
|
|
||||||
...action.config,
|
|
||||||
...state.config
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return state;
|
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