From de729dc2ffa6e1a14aa62482a961f7405b52bb01 Mon Sep 17 00:00:00 2001 From: goodmice Date: Sun, 31 Jul 2022 01:24:53 +0500 Subject: [PATCH] =?UTF-8?q?*=20=D0=A3=D0=BB=D1=83=D1=87=D1=88=D0=B5=D0=BD?= =?UTF-8?q?=20=D1=82=D0=B8=D0=BF=20SubscribeFunction=20*=20=D0=98=D1=81?= =?UTF-8?q?=D0=BF=D1=80=D0=B0=D0=B2=D0=BB=D0=B5=D0=BD=D1=8B=20=D0=BE=D1=88?= =?UTF-8?q?=D0=B8=D0=B1=D0=BA=D0=B8=20FunctionalValue?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/d3/D3MouseZone.tsx | 5 +++-- src/components/d3/plugins/D3HorizontalCursor.tsx | 4 ++-- src/components/d3/plugins/D3Tooltip.tsx | 4 ++-- src/utils/hooks/cachedFetch.ts | 2 +- src/utils/hooks/usePartialProps.ts | 2 +- 5 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/components/d3/D3MouseZone.tsx b/src/components/d3/D3MouseZone.tsx index fb85a4a..464d814 100644 --- a/src/components/d3/D3MouseZone.tsx +++ b/src/components/d3/D3MouseZone.tsx @@ -1,9 +1,10 @@ import { createContext, memo, ReactNode, useCallback, useContext, useEffect, useState } from 'react' import * as d3 from 'd3' -import '@styles/d3.less' import { ChartOffset } from './types' +import '@styles/d3.less' + export type D3MouseState = { /** Позиция мыши по оси X */ x: number @@ -13,7 +14,7 @@ export type D3MouseState = { visible: boolean } -type SubscribeFunction = (name: keyof SVGElementEventMap, handler: EventListenerOrEventListenerObject) => null | (() => boolean) +type SubscribeFunction = (name: K, handler: (this: SVGRectElement, ev: SVGElementEventMap[K]) => any) => null | (() => boolean) export type D3MouseZoneContext = { /** Состояние мыши */ diff --git a/src/components/d3/plugins/D3HorizontalCursor.tsx b/src/components/d3/plugins/D3HorizontalCursor.tsx index 2b0c687..2a3f212 100644 --- a/src/components/d3/plugins/D3HorizontalCursor.tsx +++ b/src/components/d3/plugins/D3HorizontalCursor.tsx @@ -92,8 +92,8 @@ const _D3HorizontalCursor = ({ const getXLine = useMemo(() => zone ? (() => zone().select('.tooltip-x-line')) : null, [zone]) useEffect(() => { - const onMiddleClick = (e: Event) => { - if ((e as MouseEvent).button === 1) + const onMiddleClick = (e: MouseEvent) => { + if (e.button === 1) setFixed((prev) => !prev) } diff --git a/src/components/d3/plugins/D3Tooltip.tsx b/src/components/d3/plugins/D3Tooltip.tsx index 9440e42..8622d59 100644 --- a/src/components/d3/plugins/D3Tooltip.tsx +++ b/src/components/d3/plugins/D3Tooltip.tsx @@ -98,8 +98,8 @@ function _D3Tooltip>({ const tooltipRef = useRef(null) useEffect(() => { - const onMiddleClick = (e: Event) => { - if ((e as MouseEvent).button === 1 && visible) + const onMiddleClick = (e: MouseEvent) => { + if (e.button === 1 && visible) setFixed((prev) => !prev) } diff --git a/src/utils/hooks/cachedFetch.ts b/src/utils/hooks/cachedFetch.ts index 1f559ee..f3cdaf2 100644 --- a/src/utils/hooks/cachedFetch.ts +++ b/src/utils/hooks/cachedFetch.ts @@ -1,7 +1,7 @@ import { useCallback, useEffect, useState } from 'react' import { FunctionalValue, useFunctionalValue } from './functionalValue' -export const useCachedMethod =

(method: (...props: P) => R, expires: FunctionalValue = 60, initialValue?: R | (() => R), storeValue: boolean = false) => { +export const useCachedMethod =

(method: (...props: P) => R, expires: FunctionalValue<() => number> = 60, initialValue?: R | (() => R), storeValue: boolean = false) => { const [value, setValue] = useState(initialValue) const [lastUpdate, setLastUpdate] = useState<{ date: number, props: P }>({ date: 0, props: [] as P }) const exp = useFunctionalValue(expires) diff --git a/src/utils/hooks/usePartialProps.ts b/src/utils/hooks/usePartialProps.ts index c24fca1..50121cf 100644 --- a/src/utils/hooks/usePartialProps.ts +++ b/src/utils/hooks/usePartialProps.ts @@ -1,7 +1,7 @@ import { useMemo } from 'react' import { FunctionalValue, useFunctionalValue } from './functionalValue' -export const usePartialProps = (prop: Partial | null | undefined, defaultValue: FunctionalValue): T => { +export const usePartialProps = (prop: Partial | null | undefined, defaultValue: FunctionalValue<() => T>): T => { const def = useFunctionalValue(defaultValue) const result: T = useMemo(() => {