Commit 13aae23d authored by Alejandro Celaya's avatar Alejandro Celaya Committed by Alejandro Celaya

Migrate util module to TS

parent 8a409406
/** @typedef {import('redux').Store} Store */ import type { Store } from 'redux';
/** /**
* Return an object where each key in `updateFns` is mapped to the key itself. * Return an object where each key in `updateFns` is mapped to the key itself.
* *
* @template {Record<string,Function>} T * @param reducers - Object containing reducer functions
* @param {T} reducers - Object containing reducer functions
* @return {{ [index in keyof T]: string }}
*/ */
export function actionTypes(reducers) { export function actionTypes<T extends Record<string, unknown>>(
return Object.keys(reducers).reduce((types, key) => { reducers: T
): { [index in keyof T]: string } {
return Object.keys(reducers).reduce<any>((types, key) => {
types[key] = key; types[key] = key;
return types; return types;
}, /** @type {any} */ ({})); }, {});
} }
/** /**
...@@ -20,13 +20,13 @@ export function actionTypes(reducers) { ...@@ -20,13 +20,13 @@ export function actionTypes(reducers) {
* `await` returns a Promise which resolves when a selector function, * `await` returns a Promise which resolves when a selector function,
* which reads values from a Redux store, returns non-null. * which reads values from a Redux store, returns non-null.
* *
* @template T * @param selector - Function which returns a value from the store if the
* @param {import('redux').Store} store * criteria is met or `null` otherwise.
* @param {(s: Store) => T|null} selector - Function which returns a value from the
* store if the criteria is met or `null` otherwise.
* @return {Promise<T>}
*/ */
export function awaitStateChange(store, selector) { export function awaitStateChange<T>(
store: Store,
selector: (s: Store) => T | null
): Promise<T> {
const result = selector(store); const result = selector(store);
if (result !== null) { if (result !== null) {
return Promise.resolve(result); return Promise.resolve(result);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment