update 0.15.1
This commit is contained in:
30
packages/dooringx-lib/src/hooks/useRegistFunc.ts
Normal file
30
packages/dooringx-lib/src/hooks/useRegistFunc.ts
Normal file
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
* @Author: yehuozhili
|
||||
* @Date: 2022-04-27 22:15:24
|
||||
* @LastEditors: yehuozhili
|
||||
* @LastEditTime: 2022-04-27 22:38:59
|
||||
* @FilePath: \dooringx\packages\dooringx-lib\src\hooks\useRegistFunc.ts
|
||||
*/
|
||||
|
||||
import { useEffect } from 'react';
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @export 用于简化注册函数代码
|
||||
* @param {boolean} dep 配置的开关
|
||||
* @param {('preview' | 'edit')} context 传递的环境变量
|
||||
* @param {Function} registFn 注册的函数
|
||||
*/
|
||||
export function useRegistFunc(dep: boolean, context: 'preview' | 'edit', registFn: Function) {
|
||||
useEffect(() => {
|
||||
let unRegist: Function = () => {};
|
||||
if (dep) {
|
||||
unRegist = registFn;
|
||||
}
|
||||
return () => {
|
||||
if (context === 'preview') {
|
||||
unRegist(); // 必须在预览时注销,否则影响二次点击效果,不在预览注销影响编辑时跨弹窗
|
||||
}
|
||||
};
|
||||
}, [context, dep, registFn]);
|
||||
}
|
@@ -2,7 +2,7 @@
|
||||
* @Author: yehuozhili
|
||||
* @Date: 2021-03-14 04:22:18
|
||||
* @LastEditors: yehuozhili
|
||||
* @LastEditTime: 2022-04-23 23:02:04
|
||||
* @LastEditTime: 2022-04-27 22:45:42
|
||||
* @FilePath: \dooringx\packages\dooringx-lib\src\index.tsx
|
||||
*/
|
||||
|
||||
@@ -53,6 +53,9 @@ export { changeUserValue } from './core/utils/index';
|
||||
// 用于制作快捷键
|
||||
export { CommanderItemFactory } from './core/command/abstract';
|
||||
|
||||
// 用于制作函数
|
||||
export { useRegistFunc } from './hooks/useRegistFunc';
|
||||
|
||||
export { defaultStore } from './config';
|
||||
//state
|
||||
export { focusState } from './core/focusHandler/state';
|
||||
|
Reference in New Issue
Block a user