feat:添加beforeDispatchEvent (#4102)

This commit is contained in:
hsm-lv 2022-04-20 21:25:45 +08:00 committed by GitHub
parent a629615a4c
commit e933ad1954
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 27 additions and 0 deletions

View File

@ -6,6 +6,8 @@ import {RendererConfig} from './factory';
import {ThemeInstance} from './theme'; import {ThemeInstance} from './theme';
import {Action, Api, Payload, Schema} from './types'; import {Action, Api, Payload, Schema} from './types';
import hoistNonReactStatic from 'hoist-non-react-statics'; import hoistNonReactStatic from 'hoist-non-react-statics';
import {IScopedContext} from './Scoped';
import {RendererEvent} from './utils/renderer-event';
export interface RendererEnv { export interface RendererEnv {
fetcher: (api: Api, data?: any, options?: object) => Promise<Payload>; fetcher: (api: Api, data?: any, options?: object) => Promise<Payload>;
@ -67,6 +69,23 @@ export interface RendererEnv {
* html xss * html xss
*/ */
filterHtml: (input: string) => string; filterHtml: (input: string) => string;
beforeDispatchEvent: (
e:
| string
| React.ClipboardEvent<any>
| React.DragEvent<any>
| React.ChangeEvent<any>
| React.KeyboardEvent<any>
| React.TouchEvent<any>
| React.WheelEvent<any>
| React.AnimationEvent<any>
| React.TransitionEvent<any>
| React.MouseEvent<any>,
context: any,
scoped: IScopedContext,
data: any,
broadcast?: RendererEvent<any>
) => void;
[propName: string]: any; [propName: string]: any;
} }

View File

@ -120,6 +120,14 @@ export async function dispatchEvent(
let unbindEvent = null; let unbindEvent = null;
const eventName = typeof e === 'string' ? e : e.type; const eventName = typeof e === 'string' ? e : e.type;
renderer?.props?.env?.beforeDispatchEvent?.(
e,
renderer,
scoped,
data,
broadcast
);
if (!broadcast) { if (!broadcast) {
const eventConfig = renderer?.props?.onEvent?.[eventName]; const eventConfig = renderer?.props?.onEvent?.[eventName];