mirror of
https://gitcode.com/GitHub_Trending/ji/jitsi-meet.git
synced 2026-05-15 21:37:46 +00:00
Up until now we relied on implicit loading of middlewares and reducers, through having imports in each feature's index.js. This leads to many complex import cycles which result in (sometimes) hard to fix bugs in addition to (often) breaking mobile because a web-only feature gets imported on mobile too, thanks to the implicit loading. This PR changes that to make the process explicit. Both middlewares and reducers are imported in a single place, the app entrypoint. They have been divided into 3 categories: any, web and native, which represent each of the platforms respectively. Ideally no feature should have an index.js exporting actions, action types and components, but that's a larger ordeal, so this is just the first step in getting there. In order to both set example and avoid large cycles the app feature has been refactored to not have an idex.js itself.
67 lines
2.1 KiB
JavaScript
67 lines
2.1 KiB
JavaScript
// @flow
|
|
|
|
import { APP_WILL_MOUNT } from '../app/actionTypes';
|
|
import { PersistenceRegistry, ReducerRegistry } from '../redux';
|
|
|
|
import { ADD_KNOWN_DOMAINS } from './actionTypes';
|
|
|
|
/**
|
|
* The default list of domains known to the feature base/known-domains.
|
|
* Generally, it should be in sync with the domains associated with the app
|
|
* through its manifest (in other words, Universal Links, deep linking). Anyway,
|
|
* we need a hardcoded list because it has proven impossible to programmatically
|
|
* read the information out of the app's manifests: App Store strips the
|
|
* associated domains manifest out of the app so it's never downloaded on the
|
|
* client and we did not spend a lot of effort to read the associated domains
|
|
* out of the Andorid manifest.
|
|
*/
|
|
export const DEFAULT_STATE = [
|
|
'alpha.jitsi.net',
|
|
'beta.meet.jit.si',
|
|
'meet.jit.si',
|
|
'8x8.vc'
|
|
];
|
|
|
|
const STORE_NAME = 'features/base/known-domains';
|
|
|
|
PersistenceRegistry.register(STORE_NAME);
|
|
|
|
ReducerRegistry.register(STORE_NAME, (state = DEFAULT_STATE, action) => {
|
|
switch (action.type) {
|
|
case ADD_KNOWN_DOMAINS:
|
|
return _addKnownDomains(state, action.knownDomains);
|
|
|
|
case APP_WILL_MOUNT:
|
|
// In case persistence has deserialized a weird redux state:
|
|
return _addKnownDomains(state, DEFAULT_STATE);
|
|
|
|
default:
|
|
return state;
|
|
}
|
|
});
|
|
|
|
/**
|
|
* Adds an array of known domains to the list of domains known to the feature
|
|
* base/known-domains.
|
|
*
|
|
* @param {Object} state - The redux state.
|
|
* @param {Array<string>} knownDomains - The array of known domains to add to
|
|
* the list of domains known to the feature base/known-domains.
|
|
* @private
|
|
* @returns {Object} The next redux state.
|
|
*/
|
|
function _addKnownDomains(state, knownDomains) {
|
|
// In case persistence has deserialized a weird redux state:
|
|
let nextState = Array.isArray(state) ? state : [];
|
|
|
|
if (Array.isArray(knownDomains)) {
|
|
nextState = Array.from(state);
|
|
for (let knownDomain of knownDomains) {
|
|
knownDomain = knownDomain.toLowerCase();
|
|
!nextState.includes(knownDomain) && nextState.push(knownDomain);
|
|
}
|
|
}
|
|
|
|
return nextState;
|
|
}
|