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 { MutableRefObject, useEffect, useRef, useState } from "react"; | |
type AsyncResult<T> = { | |
status: AsyncStatus; | |
data?: T; | |
error?: Error; | |
}; | |
enum AsyncStatus { | |
Loading, |
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
body { | |
font-size: calc([minimum size] + ([maximum size] - [minimum size]) * ((100vw - [minimum viewport width]) / ([maximum viewport width] - [minimum viewport width]))); | |
} |
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 const clamp = (num: number, min: number, max: number): number => | |
Math.max(min, Math.min(max, num)) |
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 { useRef } from 'react' | |
/** | |
* Создает константное значение в функциональном React компоненте | |
* useMemo не дает гарантий, что функция определения значения не вызовется повторно | |
* https://reactjs.org/docs/hooks-faq.html#how-to-create-expensive-objects-lazily | |
* https://reactjs.org/docs/hooks-reference.html#usememo | |
* | |
* @param defineValue функция определения значения | |
*/ |
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 { MutableRefObject, useEffect, useRef } from 'react' | |
export const useSyncRef = <T>(value: T): MutableRefObject<T> => { | |
const ref = useRef<T>(value) | |
useEffect(() => { | |
ref.current = value | |
}, [value]) | |
return ref |
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/ban-types */ | |
import { Reducer, useCallback, useReducer } from 'react' | |
import { useConstant } from 'hooks/useConstant' | |
const reducerCreator = | |
<S extends object>(filter?: (prev: S, curr: S) => boolean) => | |
(state: S, update: (prevState: S) => S | void) => { | |
const nextState = update(state) | |
return nextState === void 0 || (filter && filter(state, nextState)) |
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 * as getRandomWord from "random-words"; | |
export const getRandomFloat = <T extends number = number>(min = 0, max = 1): T => { | |
return (Math.random() * (max - min) + min) as T; | |
}; | |
export const getRandomInt = <T extends number = number>(min = 0, max = 1): T => { | |
if (min === max) return min as T; | |
return Math.round(getRandomFloat(min, max)) as T; |
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 { | |
Effect, | |
Store, | |
combine, | |
guard, | |
createEvent, | |
restore, | |
sample, | |
} from "effector"; | |
import { status as patronumStatus } from "patronum"; |
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 { combine, createEvent, createStore, Event, guard, sample, StoreValue } from "effector"; | |
export const createUndoRedo = <S extends unknown>({ defaultState, filter, limit, name }: UndoRedoOptions<S>) => { | |
const storeName = name || "unknown-store"; | |
const $present = createStore(defaultState, { name: `history/${storeName}/present` }); | |
const limitPerTime = Math.round(limit / 2); | |
const $past = createStore<S[]>([], { name: `history/${storeName}/past` }); | |
const $future = createStore<S[]>([], { name: `history/${storeName}/future` }); |
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
{ | |
// Use IntelliSense to learn about possible attributes. | |
// Hover to view descriptions of existing attributes. | |
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 | |
// https://github.com/wclr/ts-node-dev/issues/9 | |
"version": "0.2.0", | |
"configurations": [ | |
{ | |
"name":"ts-node (src/index.ts)", | |
"type":"node", |
NewerOlder