Skip to content

Commit

Permalink
fix(runtime): 修复@tarojs/plugin-inject使用报错的问题,fix #9783
Browse files Browse the repository at this point in the history
  • Loading branch information
Chen-jj committed Jul 20, 2021
1 parent 6c70816 commit d5b6bce
Showing 1 changed file with 21 additions and 17 deletions.
38 changes: 21 additions & 17 deletions packages/taro-runtime/src/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,20 +45,6 @@ export class Hooks implements IHooks {
@inject(SERVICE_IDENTIFIER.onRemoveAttribute) @optional()
public onRemoveAttribute?: OnRemoveAttribute

@inject(SERVICE_IDENTIFIER.modifyMpEvent) @optional()
private modifyMpEventImpls?: ModifyMpEvent[]

public modifyMpEvent (e: MpEvent) {
this.modifyMpEventImpls?.forEach(fn => fn(e))
}

@multiInject(SERVICE_IDENTIFIER.modifyTaroEvent) @optional()
private modifyTaroEventImpls?: ModifyTaroEvent[]

public modifyTaroEvent (e: TaroEvent, element: TaroElement) {
this.modifyTaroEventImpls?.forEach(fn => fn(e, element))
}

@inject(SERVICE_IDENTIFIER.batchedEventUpdates) @optional()
public batchedEventUpdates?: BatchedEventUpdates

Expand All @@ -71,9 +57,6 @@ export class Hooks implements IHooks {
@inject(SERVICE_IDENTIFIER.getDOMNode) @optional()
public getDOMNode?: GetDOMNode

@inject(SERVICE_IDENTIFIER.initNativeApi) @optional()
public initNativeApi?: InitNativeApi

@inject(SERVICE_IDENTIFIER.modifyHydrateData) @optional()
public modifyHydrateData?: ModifyHydrateData

Expand All @@ -85,4 +68,25 @@ export class Hooks implements IHooks {

@inject(SERVICE_IDENTIFIER.onAddEvent) @optional()
public onAddEvent?: OnAddEvent

@multiInject(SERVICE_IDENTIFIER.modifyMpEvent) @optional()
private modifyMpEventImpls?: ModifyMpEvent[]

public modifyMpEvent (e: MpEvent) {
this.modifyMpEventImpls?.forEach(fn => fn(e))
}

@multiInject(SERVICE_IDENTIFIER.modifyTaroEvent) @optional()
private modifyTaroEventImpls?: ModifyTaroEvent[]

public modifyTaroEvent (e: TaroEvent, element: TaroElement) {
this.modifyTaroEventImpls?.forEach(fn => fn(e, element))
}

@multiInject(SERVICE_IDENTIFIER.initNativeApi) @optional()
public initNativeApiImpls?: InitNativeApi[]

public initNativeApi (taro: Record<string, any>) {
this.initNativeApiImpls?.forEach(fn => fn(taro))
}
}

0 comments on commit d5b6bce

Please sign in to comment.