1 4
import stopPropagation, { validate as validatePropagation, isPropagationStopped } from './stopPropagation';
2 4
import { SYNTHETIC_TYPES, DEPRECATED_CATCH_TYPE } from './constants';
3
import VNode from '../VNode';
4

5 4
function isSyntheticType(inputType: string) {
6 4
  if (DEPRECATED_CATCH_TYPE === inputType) {
7 4
    console.warn(
8
      'DEPRECATION: remax 已支持在 onClick 事件中使用 stopPropagation 阻止事件冒泡,请尽量不要使用 catchClick'
9
    );
10
  }
11

12 4
  return !!SYNTHETIC_TYPES.find(type => type === inputType);
13
}
14

15 4
function createBaseSyntheticEvent(node: VNode, eventType: string, nativeEvent: any) {
16 4
  if (!nativeEvent) {
17 4
    return;
18
  }
19

20
  // 添加阻止冒泡方法
21 4
  nativeEvent.stopPropagation = () => {
22 4
    stopPropagation(node, eventType);
23
  };
24

25 4
  return nativeEvent;
26
}
27

28 4
export function createCallbackProxy(eventType: string, node: VNode, callback: (...params: any) => any) {
29 4
  if (!isSyntheticType(eventType)) {
30 4
    return callback;
31
  }
32

33 4
  return function (nativeEvent: any, ...restParams: any) {
34 4
    const syntheticEvent = createBaseSyntheticEvent(node, eventType, nativeEvent);
35

36 4
    if (isPropagationStopped[eventType]) {
37 4
      validatePropagation(node, eventType);
38 4
      return;
39
    }
40

41 4
    return callback(syntheticEvent, ...restParams);
42
  };
43
}

Read our documentation on viewing source code .

Loading