mirror of
https://gitcode.com/GitHub_Trending/ji/jitsi-meet.git
synced 2025-12-30 11:22:31 +00:00
I'm not saying that the two commits in question were wrong or worse than what I'm offering. Anyway, I think what I'm offering brings: * Compliance with expectations i.e. the middleware doesn't compute the next state from the current state, the reducer does; * Clarity and/or simplicity i.e. there's no global variable (reqIndex), there's no need for the term "index" (a.k.a "reqIndex") in the redux store. * By renaming net-interceptor to network-activity feels like it's preparing the feature to implement a NetworkActivityIndicator React Component which will take on more of the knowledge about the specifics of what is the network activity redux state exactly, is it maintained by interception or some other mechanism, and abstracts it in the feature itself allowing outsiders to merely render a React Component.
61 lines
1.4 KiB
JavaScript
61 lines
1.4 KiB
JavaScript
/* @flow */
|
|
|
|
import { ReducerRegistry, set } from '../../base/redux';
|
|
|
|
import {
|
|
_ADD_NETWORK_REQUEST,
|
|
_REMOVE_ALL_NETWORK_REQUESTS,
|
|
_REMOVE_NETWORK_REQUEST
|
|
} from './actionTypes';
|
|
|
|
/**
|
|
* The initial redux state of the feature network-activity.
|
|
*
|
|
* @type {{
|
|
* requests: Map
|
|
* }}
|
|
*/
|
|
const _INITIAL_STATE = {
|
|
/**
|
|
* The ongoing network requests i.e. the network request which have been
|
|
* added to the redux store/state and have not been removed.
|
|
*
|
|
* @type {Map}
|
|
*/
|
|
requests: new Map()
|
|
};
|
|
|
|
ReducerRegistry.register(
|
|
'features/network-activity',
|
|
(state = _INITIAL_STATE, action) => {
|
|
switch (action.type) {
|
|
case _ADD_NETWORK_REQUEST: {
|
|
const {
|
|
type, // eslint-disable-line no-unused-vars
|
|
|
|
request: key,
|
|
...value
|
|
} = action;
|
|
const requests = new Map(state.requests);
|
|
|
|
requests.set(key, value);
|
|
|
|
return set(state, 'requests', requests);
|
|
}
|
|
|
|
case _REMOVE_ALL_NETWORK_REQUESTS:
|
|
return set(state, 'requests', _INITIAL_STATE.requests);
|
|
|
|
case _REMOVE_NETWORK_REQUEST: {
|
|
const { request: key } = action;
|
|
const requests = new Map(state.requests);
|
|
|
|
requests.delete(key);
|
|
|
|
return set(state, 'requests', requests);
|
|
}
|
|
}
|
|
|
|
return state;
|
|
});
|