HarmonyOS除了eventHub还有什么事件机制可以传递WrappedBuilder吗?

之前准备使用emitter。

export const addInteractive = (model: InteractiveModel) => { 
  emitter.emit(InteractiveEvent.ADD, { data: model }) 
} 
export class InteractiveModel { 
  type: InteractiveType = InteractiveType.NONE 
  stick: boolean = false 
  reachType: ReachType = ReachType.ABOVE 
  builderWrap: WrappedBuilder<[ESObject]> = wrapBuilder(defaultBuilder) 
  param: ParamType = '' 
  constructor(type: InteractiveType, builderWrap: WrappedBuilder<[ESObject]>, param: ParamType = '') { 
    this.type = type 
    this.stick = InteractiveTypeMap[type].stick 
    this.reachType = InteractiveTypeMap[type].reachType 
    this.builderWrap = builderWrap 
    this.param = param 
  } 
}
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.

传递之后, data为undefined。搜索发现是emitter目前发送事件时传递的数据,支持数据类型包括Array、ArrayBuffer、Boolean、DataView、Date、Error、Map、Number、Object、Primitive(除了symbol)、RegExp、Set、String、TypedArray,有什么其他事件机制吗?

HarmonyOS
2024-09-06 11:23:47
641浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
FengTianYa

可以在事件接收方使用as进行类型转换:data as Object as InteractiveModel,如果是包含方法的对象需要添加@Sendable标签。

分享
微博
QQ
微信
回复
2024-09-06 15:44:57
相关问题
是否有一对多事件传递机制
2816浏览 • 1回复 待解决
HarmonyOS 能否通过eventHub传递Want数据
621浏览 • 1回复 待解决
HarmonyOS 接收不到eventhub事件
774浏览 • 1回复 待解决
HarmonyOS eventHub注册和移除事件监听
1395浏览 • 1回复 待解决
HarmonyOS中的消息传递机制如何工作?
895浏览 • 0回复 待解决