This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* eslint-disable @typescript-eslint/no-explicit-any */ | |
import { fromJS, OrderedMap } from 'immutable'; | |
interface ObjectWithId { | |
id: number; | |
[property: string]: any; | |
} | |
export const toOrderedMap = <T = any>(arr: ObjectWithId[]): OrderedMap<number, T> => { | |
return arr.reduce( |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Map } from 'immutable'; | |
type ExpectedPrimitive = boolean | number | string | symbol | null; | |
/** | |
* Generic конвертор неиммутабельного интерфейса в иммутабельный. | |
* В отличие от RecordOf вычисляет return type для getIn и вложенных полей. | |
*/ | |
// eslint-disable-next-line @typescript-eslint/no-explicit-any | |
export interface ImmutableFrom<Interface> extends Map<string, any> { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export default function* foreach(array, fn, context) { | |
let i = 0; | |
for (; i < array.length; i++) { | |
yield* fn.call(context, array[i], i, array); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { useEffect, useRef } from 'react'; | |
export const useInterval = (callback: () => void, timeout?: number): void => { | |
const intervalId = useRef<number>(); | |
const savedCallback = useRef<() => void>(); | |
useEffect(() => { | |
savedCallback.current = callback; | |
}, [callback]); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import createStub from 'raf-stub'; | |
import { animate, AnimateUtilParams } from '../animate'; | |
describe('`animate` util tests', () => { | |
const params = {} as AnimateUtilParams; | |
const DEFAULT_DURATION = 300; | |
const FRAME_DURATION = 10; | |
const DEFAULT_FRAMES_COUNT = DEFAULT_DURATION / FRAME_DURATION + 1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function isObject(item) { | |
return (item && typeof item === 'object' && !Array.isArray(item)); | |
} | |
function mergeDeep(target, ...sources) { | |
if (!sources.length) return target; | |
const source = sources.shift(); | |
if (isObject(target) && isObject(source)) { | |
for (const key in source) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export interface RefCounter<T = unknown> { | |
getCount(item: T): number | |
add(item: T): void | |
remove(item: T): void | |
} | |
export const getStringRefCounter = (): RefCounter<string> => { | |
const values: Record<string, number | undefined> = {} | |
const getCount = (key: string): number => values[key] || 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export interface ComparableMap<K = string, V = unknown> { | |
keys: K[] | |
get(key: K): V | undefined | |
add(key: K, value: V): void | |
remove(key: K): V | undefined | |
} | |
/** | |
* We will use it where we can not use the default Map as the Map class do not allow custom compare function. | |
* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export interface SagaWithArguments<T = any> { | |
saga: (argument?: T) => Iterator<any> | |
argument?: T | |
} | |
export type SagaRegistration<T = any> = (() => Iterator<any>) | SagaWithArguments<T> | |
export const sagaEquals = (sagaA: SagaRegistration, sagaB: SagaRegistration): boolean => { | |
if (typeof sagaA === 'function' && typeof sagaB === 'function') { | |
return sagaA === sagaB |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type ExtractReturnTypes<T extends ((...args: unknown[]) => unknown)[]> = [ | |
...{ [K in keyof T]: T[K] extends ((...args: unknown[]) => infer R) ? R : never } | |
] |
OlderNewer