ref: Convert registries to TS (#11865)
This commit is contained in:
parent
08173ac1df
commit
7995c7ed00
|
@ -143,6 +143,7 @@
|
|||
"@babel/preset-react": "7.16.0",
|
||||
"@babel/runtime": "7.16.0",
|
||||
"@jitsi/eslint-config": "4.0.0",
|
||||
"@types/js-md5": "0.4.3",
|
||||
"@types/lodash": "4.14.182",
|
||||
"@types/react": "17.0.14",
|
||||
"@types/react-native": "0.67.6",
|
||||
|
@ -5464,6 +5465,12 @@
|
|||
"resolved": "https://registry.npmjs.org/@types/js-cookie/-/js-cookie-2.2.7.tgz",
|
||||
"integrity": "sha512-aLkWa0C0vO5b4Sr798E26QgOkss68Un0bLjs7u9qxzPT5CG+8DuNTffWES58YzJs3hrVAOs1wonycqEBqNJubA=="
|
||||
},
|
||||
"node_modules/@types/js-md5": {
|
||||
"version": "0.4.3",
|
||||
"resolved": "https://registry.npmjs.org/@types/js-md5/-/js-md5-0.4.3.tgz",
|
||||
"integrity": "sha512-BIga/WEqTi35ccnGysOuO4RmwVnpajv9oDB/sDQSY2b7/Ac7RyYR30bv7otZwByMvOJV9Vqq6/O1DFAnOzE4Pg==",
|
||||
"dev": true
|
||||
},
|
||||
"node_modules/@types/json-schema": {
|
||||
"version": "7.0.9",
|
||||
"resolved": "https://registry.npmjs.org/@types/json-schema/-/json-schema-7.0.9.tgz",
|
||||
|
@ -24566,6 +24573,12 @@
|
|||
"resolved": "https://registry.npmjs.org/@types/js-cookie/-/js-cookie-2.2.7.tgz",
|
||||
"integrity": "sha512-aLkWa0C0vO5b4Sr798E26QgOkss68Un0bLjs7u9qxzPT5CG+8DuNTffWES58YzJs3hrVAOs1wonycqEBqNJubA=="
|
||||
},
|
||||
"@types/js-md5": {
|
||||
"version": "0.4.3",
|
||||
"resolved": "https://registry.npmjs.org/@types/js-md5/-/js-md5-0.4.3.tgz",
|
||||
"integrity": "sha512-BIga/WEqTi35ccnGysOuO4RmwVnpajv9oDB/sDQSY2b7/Ac7RyYR30bv7otZwByMvOJV9Vqq6/O1DFAnOzE4Pg==",
|
||||
"dev": true
|
||||
},
|
||||
"@types/json-schema": {
|
||||
"version": "7.0.9",
|
||||
"resolved": "https://registry.npmjs.org/@types/json-schema/-/json-schema-7.0.9.tgz",
|
||||
|
|
|
@ -148,6 +148,7 @@
|
|||
"@babel/preset-react": "7.16.0",
|
||||
"@babel/runtime": "7.16.0",
|
||||
"@jitsi/eslint-config": "4.0.0",
|
||||
"@types/js-md5": "0.4.3",
|
||||
"@types/lodash": "4.14.182",
|
||||
"@types/react": "17.0.14",
|
||||
"@types/react-native": "0.67.6",
|
||||
|
|
|
@ -1,14 +1,11 @@
|
|||
/* @flow */
|
||||
|
||||
import { applyMiddleware } from 'redux';
|
||||
import type { Middleware } from 'redux';
|
||||
import { applyMiddleware, Middleware } from 'redux';
|
||||
|
||||
/**
|
||||
* A registry for Redux middleware, allowing features to register their
|
||||
* middleware without needing to create additional inter-feature dependencies.
|
||||
*/
|
||||
class MiddlewareRegistry {
|
||||
_elements: Array<Middleware<*, *>>;
|
||||
_elements: Array<Middleware<any, any>>;
|
||||
|
||||
/**
|
||||
* Creates a MiddlewareRegistry instance.
|
||||
|
@ -31,8 +28,7 @@ class MiddlewareRegistry {
|
|||
* be included (such as middleware from third-party modules).
|
||||
* @returns {Middleware}
|
||||
*/
|
||||
applyMiddleware(...additional: Array<Middleware<*, *>>) {
|
||||
// $FlowExpectedError
|
||||
applyMiddleware(...additional: Array<Middleware<any, any>>) {
|
||||
return applyMiddleware(...this._elements, ...additional);
|
||||
}
|
||||
|
||||
|
@ -44,7 +40,7 @@ class MiddlewareRegistry {
|
|||
* @param {Middleware} middleware - A Redux middleware.
|
||||
* @returns {void}
|
||||
*/
|
||||
register(middleware: Middleware<*, *>) {
|
||||
register(middleware: Middleware<any, any>) {
|
||||
this._elements.push(middleware);
|
||||
}
|
||||
}
|
|
@ -1,12 +1,15 @@
|
|||
// @flow
|
||||
|
||||
/* eslint-disable import/order */
|
||||
// @ts-ignore
|
||||
import Bourne from '@hapi/bourne';
|
||||
|
||||
// @ts-ignore
|
||||
import { jitsiLocalStorage } from '@jitsi/js-utils';
|
||||
import md5 from 'js-md5';
|
||||
|
||||
// @ts-ignore
|
||||
import logger from './logger';
|
||||
|
||||
declare var __DEV__;
|
||||
declare let __DEV__: any;
|
||||
|
||||
/**
|
||||
* The name of the {@code localStorage} store where the app persists its values.
|
||||
|
@ -30,8 +33,8 @@ declare type PersistencyConfigMap = { [name: string]: ElementConfig };
|
|||
* persisted and also handles the persistency calls too.
|
||||
*/
|
||||
class PersistenceRegistry {
|
||||
_checksum: string;
|
||||
_defaultStates: { [name: string ]: ?Object} = {};
|
||||
_checksum = '';
|
||||
_defaultStates: { [name: string ]: Object|undefined} = {};
|
||||
_elements: PersistencyConfigMap = {};
|
||||
|
||||
/**
|
||||
|
@ -43,7 +46,7 @@ class PersistenceRegistry {
|
|||
* @returns {Object}
|
||||
*/
|
||||
getPersistedState() {
|
||||
let filteredPersistedState = {};
|
||||
let filteredPersistedState: any = {};
|
||||
|
||||
// localStorage key per feature
|
||||
for (const subtreeName of Object.keys(this._elements)) {
|
||||
|
@ -134,7 +137,7 @@ class PersistenceRegistry {
|
|||
*/
|
||||
register(
|
||||
name: string,
|
||||
config?: ElementConfig = true,
|
||||
config: ElementConfig = true,
|
||||
defaultState?: Object) {
|
||||
this._elements[name] = config;
|
||||
this._defaultStates[name] = defaultState;
|
||||
|
@ -165,8 +168,8 @@ class PersistenceRegistry {
|
|||
* @private
|
||||
* @returns {Object}
|
||||
*/
|
||||
_getFilteredState(state: Object) {
|
||||
const filteredState = {};
|
||||
_getFilteredState(state: any): any {
|
||||
const filteredState: any = {};
|
||||
|
||||
for (const name of Object.keys(this._elements)) {
|
||||
if (state[name]) {
|
||||
|
@ -189,8 +192,8 @@ class PersistenceRegistry {
|
|||
* @private
|
||||
* @returns {Object}
|
||||
*/
|
||||
_getFilteredSubtree(subtree, subtreeConfig) {
|
||||
let filteredSubtree;
|
||||
_getFilteredSubtree(subtree: any, subtreeConfig: any) {
|
||||
let filteredSubtree: any;
|
||||
|
||||
if (typeof subtreeConfig === 'object') {
|
||||
// Only a filtered subtree gets persisted as specified by
|
||||
|
@ -219,7 +222,7 @@ class PersistenceRegistry {
|
|||
* @private
|
||||
* @returns {Object}
|
||||
*/
|
||||
_getPersistedSubtree(subtreeName, subtreeConfig, subtreeDefaults) {
|
||||
_getPersistedSubtree(subtreeName: string, subtreeConfig: Object, subtreeDefaults?: Object) {
|
||||
let persistedSubtree = jitsiLocalStorage.getItem(subtreeName);
|
||||
|
||||
if (persistedSubtree) {
|
||||
|
@ -254,7 +257,7 @@ class PersistenceRegistry {
|
|||
* @param {?Object} defaults - The defaults, if any.
|
||||
* @returns {Object}
|
||||
*/
|
||||
_mergeDefaults(subtree: Object, defaults: ?Object) {
|
||||
_mergeDefaults(subtree: Object, defaults?: Object) {
|
||||
if (!defaults) {
|
||||
return subtree;
|
||||
}
|
|
@ -36,7 +36,6 @@ class ReducerRegistry {
|
|||
* @returns {Function}
|
||||
*/
|
||||
combineReducers(additional: NameReducerMap<any> = {}) {
|
||||
// $FlowExpectedError
|
||||
return combineReducers({
|
||||
...this._elements,
|
||||
...additional
|
||||
|
|
|
@ -1,8 +1,9 @@
|
|||
// @flow
|
||||
|
||||
import type { Store } from 'redux';
|
||||
/* eslint-disable import/order */
|
||||
import { Store } from 'redux';
|
||||
|
||||
import { equals } from './functions';
|
||||
|
||||
// @ts-ignore
|
||||
import logger from './logger';
|
||||
|
||||
/**
|
||||
|
@ -20,7 +21,7 @@ import logger from './logger';
|
|||
* Immutable!
|
||||
*/
|
||||
type Listener
|
||||
= (selection: any, store: Store<*, *>, prevSelection: any) => void;
|
||||
= (selection: any, store: Store<any, any>, prevSelection: any) => void;
|
||||
|
||||
/**
|
||||
* The type selector supported for registration with
|
||||
|
@ -47,7 +48,7 @@ type RegistrationOptions = {
|
|||
* @property {boolean} [deepEquals=false] - Whether or not a deep equals check should be performed on the selection
|
||||
* returned by {@link Selector}.
|
||||
*/
|
||||
deepEquals: ?boolean
|
||||
deepEquals?: boolean
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -66,7 +67,7 @@ type SelectorListener = {
|
|||
/**
|
||||
* The {@link RegistrationOptions} passed during the registration to be applied on the listener.
|
||||
*/
|
||||
options: ?RegistrationOptions,
|
||||
options?: RegistrationOptions,
|
||||
|
||||
/**
|
||||
* The {@code Selector} which selects values whose changes are listened to
|
||||
|
@ -86,11 +87,6 @@ class StateListenerRegistry {
|
|||
*/
|
||||
_selectorListeners: Set<SelectorListener> = new Set();
|
||||
|
||||
_listener: ({
|
||||
prevSelections: Map<SelectorListener, any>,
|
||||
store: Store<*, *>
|
||||
}) => void;
|
||||
|
||||
/**
|
||||
* Invoked by a specific redux store any time an action is dispatched, and
|
||||
* some part of the state (tree) may potentially have changed.
|
||||
|
@ -102,7 +98,7 @@ class StateListenerRegistry {
|
|||
*/
|
||||
_listener({ prevSelections, store }: {
|
||||
prevSelections: Map<SelectorListener, any>,
|
||||
store: Store<*, *>
|
||||
store: Store<any, any>
|
||||
}) {
|
||||
for (const selectorListener of this._selectorListeners) {
|
||||
const prevSelection = prevSelections.get(selectorListener);
|
||||
|
@ -140,7 +136,7 @@ class StateListenerRegistry {
|
|||
* @param {RegistrationOptions} [options] - Any options to be applied to the registration.
|
||||
* @returns {void}
|
||||
*/
|
||||
register(selector: Selector, listener: Listener, options: ?RegistrationOptions) {
|
||||
register(selector: Selector, listener: Listener, options?: RegistrationOptions) {
|
||||
this._selectorListeners.add({
|
||||
listener,
|
||||
selector,
|
||||
|
@ -157,7 +153,7 @@ class StateListenerRegistry {
|
|||
* {@code StateListenerRegistry} is to {@code subscribe}.
|
||||
* @returns {void}
|
||||
*/
|
||||
subscribe(store: Store<*, *>) {
|
||||
subscribe(store: Store<any, any>) {
|
||||
// XXX If StateListenerRegistry is not utilized by the app to listen to
|
||||
// state changes, do not bother subscribing to the store at all.
|
||||
if (this._selectorListeners.size) {
|
Loading…
Reference in New Issue