Skip to content

Commit

Permalink
feat(runtime): 增加 onAddEvent 钩子 (#9210)
Browse files Browse the repository at this point in the history
Co-authored-by: Li,Weitao <[email protected]>
  • Loading branch information
Chen-jj and luckyadam authored Apr 27, 2021
1 parent 0ecefaf commit 622ca7a
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
2 changes: 2 additions & 0 deletions packages/taro-runtime/src/dom/event_target.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { isArray, isObject, warn } from '@tarojs/shared'
import { CurrentReconciler } from '../reconciler'

interface EventListenerOptions {
capture?: boolean;
Expand All @@ -17,6 +18,7 @@ export class TaroEventTarget {
public __handlers: Record<string, EventHandler[]> = {}

public addEventListener (type: string, handler: EventHandler, options?: boolean | AddEventListenerOptions) {
CurrentReconciler.onAddEvent?.(type, handler, options)
if (type === 'regionchange') {
// map 组件的 regionchange 事件非常特殊,详情:https://github.com/NervJS/taro/issues/5766
this.addEventListener('begin', handler, options)
Expand Down
3 changes: 3 additions & 0 deletions packages/taro-runtime/src/reconciler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import type { NodeType } from './dom/node_types'
import type { EventsType } from './emitter/emitter'
import { TaroEvent, MpEvent } from './dom/event'
import type { Func } from './utils/types'
import type { EventHandler } from './dom/event_target'

type Inst = Instance<PageProps>

Expand Down Expand Up @@ -41,6 +42,8 @@ export interface Reconciler<Instance, DOMElement = TaroElement, TextElement = Ta

batchedEventUpdates?(cb: () => void): void

onAddEvent?(type: string, handler: EventHandler, options: any): void

// h5
createPullDownComponent?(el: Instance, path: string, framework, customWrapper?: any)

Expand Down

0 comments on commit 622ca7a

Please sign in to comment.