qyfeng03
在文件中开启flow检查
// @flow
import { snakeCase } from 'lodash'; | |
import { camelCase, kebabCase, mapKeys, transform } from 'lodash/fp'; | |
import React, { useEffect } from 'react'; | |
import { useHistory, useLocation } from 'react-router-dom'; | |
export type SearchParamObject<ParamList extends string> = { | |
[key in ParamList]: string; | |
}; | |
export interface SetSearchParamAction<ParamList extends string> { |
export async function asyncReduce<IterationItem, AccValue>( | |
array: IterationItem[], | |
reducer: (accumulate: AccValue, current: IterationItem) => AccValue | Promise<AccValue>, | |
initValue: AccValue, | |
): Promise<AccValue> { | |
let accumulate = typeof initValue === 'object' ? Object.create((initValue as unknown) as object) : initValue; | |
for (const item of array) { | |
accumulate = await reducer(accumulate, item); | |
} |
import React, { useState, useEffect, useRef } from 'react'; | |
import clamp from 'lodash/clamp'; | |
export type VScrollController = { scrollTo: (top: number) => void }; | |
const DEFAULT_DURATION = '200ms'; | |
const DEFAULT_TIMEING_FUNCTION = 'ease-in-out'; | |
/** | |
* virtual scroll 的实现 |
export interface UseEchartsOptions { | |
/** | |
* render root | |
*/ | |
renderRootRef: React.RefObject<HTMLDivElement | HTMLCanvasElement>; | |
/** | |
* `setOption` 1st param object | |
*/ | |
echartsOption: EChartOption; | |
/** |
function toCamelCase(str) { | |
return str.toLowerCase().replace(/(?:(^.)|(\s+.))/g, function(match) { | |
return match.charAt(match.length-1).toUpperCase(); | |
}); | |
} |
export const debounce: <T extends []>(fn: (...args: T) => void, wait: number) => (...args: T) => void = (fn, wait) => { | |
let timeout = -1; | |
return (...args) => { | |
if (timeout !== -1) clearTimeout(timeout); | |
timeout = setTimeout(() => { | |
fn(...args); | |
}, wait); | |
}; | |
}; |
const { createFilter } = require("@rollup/pluginutils"); | |
const pathTemplate =(path)=> ` | |
var path = ${path}; | |
export default path; | |
` | |
module.exports = function filePath( | |
options = { | |
include: ["**/*.ejs"], |
/** | |
* 可选的 组件注销时调用的回调函数 | |
* | |
* 可以用来清理副作用,避免内存泄漏 | |
*/ | |
type HandlerCleanup = VoidFunction | |
/** | |
* 组件捕获后执行的回调函数 | |
*/ |
const DEFAULT_POLLING_INTERVAL = 300 | |
interface Polling { | |
(cb: () => void, timeout?: number): { | |
/** stop polling */ | |
stopPolling: () => void | |
} | |
} | |
/** |