jiti-meet/react/features/base/redux/MiddlewareRegistry.ts

54 lines
1.5 KiB
TypeScript
Raw Normal View History

import { Middleware, applyMiddleware } from 'redux';
2017-02-02 15:45:34 +00:00
import { IReduxState, IStore } from '../../app/types';
/**
* A registry for Redux middleware, allowing features to register their
* middleware without needing to create additional inter-feature dependencies.
*/
class MiddlewareRegistry {
2022-07-15 12:33:09 +00:00
_elements: Array<Middleware<any, any>>;
2017-02-02 15:45:34 +00:00
/**
* Creates a MiddlewareRegistry instance.
*/
constructor() {
/**
* The set of registered middleware.
2017-02-02 15:45:34 +00:00
*
* @private
2017-02-03 16:17:20 +00:00
* @type {Middleware[]}
*/
2017-02-02 15:45:34 +00:00
this._elements = [];
}
/**
* Applies all registered middleware into a store enhancer.
* (@link http://redux.js.org/docs/api/applyMiddleware.html).
*
2017-02-02 15:45:34 +00:00
* @param {Middleware[]} additional - Any additional middleware that need to
* be included (such as middleware from third-party modules).
2017-02-02 15:45:34 +00:00
* @returns {Middleware}
*/
2022-07-15 12:33:09 +00:00
applyMiddleware(...additional: Array<Middleware<any, any>>) {
2019-03-19 15:42:25 +00:00
return applyMiddleware(...this._elements, ...additional);
}
/**
* Adds a middleware to the registry.
*
* The method is to be invoked only before {@link #applyMiddleware()}.
*
2017-02-02 15:45:34 +00:00
* @param {Middleware} middleware - A Redux middleware.
* @returns {void}
*/
register(middleware: Middleware<any, IReduxState, IStore['dispatch']>) {
2017-02-02 15:45:34 +00:00
this._elements.push(middleware);
}
}
/**
* The public singleton instance of the MiddlewareRegistry class.
*/
export default new MiddlewareRegistry();