Saúl Ibarra Corretgé 6e679f952f redux: refactor loading of middlewares and reducers
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.
2020-06-16 11:24:15 +02:00

57 lines
1.3 KiB
JavaScript

// @flow
import { getDefaultURL } from '../../app/functions';
import { APP_WILL_MOUNT } from '../app';
import { SET_ROOM } from '../conference';
import { MiddlewareRegistry } from '../redux';
import { parseURIString } from '../util';
import { addKnownDomains } from './actions';
MiddlewareRegistry.register(store => next => action => {
const result = next(action);
switch (action.type) {
case APP_WILL_MOUNT:
_appWillMount(store);
break;
case SET_ROOM:
_setRoom(store);
break;
}
return result;
});
/**
* Adds the domain of the app's {@code defaultURL} to the list of domains known
* to the feature base/known-domains.
*
* @param {Object} store - The redux store.
* @private
* @returns {Promise}
*/
function _appWillMount({ dispatch, getState }) {
const defaultURL = parseURIString(getDefaultURL(getState));
dispatch(addKnownDomains(defaultURL.host));
}
/**
* Adds the domain of {@code locationURL} to the list of domains known to the
* feature base/known-domains.
*
* @param {Object} store - The redux store.
* @private
* @returns {Promise}
*/
function _setRoom({ dispatch, getState }) {
const { locationURL } = getState()['features/base/connection'];
let host;
locationURL
&& (host = locationURL.host)
&& dispatch(addKnownDomains(host));
}