Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

希望view, viewed, hide, hidden事件中加入一些额外的上下文信息 #593

Open
qiangbro opened this issue Mar 20, 2023 · 0 comments

Comments

@qiangbro
Copy link

qiangbro commented Mar 20, 2023

Is your feature request related to a problem? Please describe.

  1. 希望通过一种方式来辨别view, viewed, hide, hidden这些事件是由用户主动点击viewerjs自身的控件触发的,还是编程式调用viewer实例的view()、hide()等函数触发的。
  2. 当编程式调用viewer实例的view()函数触发view, viewed事件时,希望这些事件能与对应的view()方法共享同一个上下文对象。例如,调用view时我有一个上下文对象 {calledFrom:'component1'},当收到view事件时,希望从事件中取回这次调用view函数时传入的这个对象{calledFrom:'component1'},用来追溯与本次view事件对应的调用view函数时的系统状态之用。hide函数、hide事件、hidden事件也是同理。

Describe the solution you'd like
可行的建议方案:

  1. 在view, viewed, hide, hidden事件的event对象中加入一个"triggeredBy"字段,
    例如:
    当事件是由用户主动点击触发时,event.triggeredBy = 'actively_user_action'
    当事件是由编程式的函数调用触发时,event.triggeredBy = 'programmed_call'

  2. view()、hide()函数加入一个triggerContext参数,赋值到事件的event对象上,
    例如:
    当调用viewer打开了一个图片,参数triggerContext传入了一个上下文对象,

viewer.view({triggerContext: {calledFrom:'component1'}})

然后产生的view事件的event.triggerContext能够访问到这个上下问对象。

console.log(event.triggerContext)
// {calledFrom:'component1'}

Describe alternatives you've considered
目前为了共享view函数与view事件的上下文,我在调用view函数时,会往viewer实例上赋值一个viewTriggerContext对象,收到view事件后,从viewer实例取回并删除viewTriggerContext对象,这样显然相当不优雅。hide函数与hide事件之间共享上下文也是同理。

Additional context

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants