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

请问JS调用原生方法后,可以多次callBack回调给JS吗? #33

Closed
sunsang opened this issue Apr 15, 2021 · 8 comments
Closed

Comments

@sunsang
Copy link

sunsang commented Apr 15, 2021

请问JS调用原生方法后,可以多次callBack回调给JS吗?

@Lision
Copy link
Owner

Lision commented Apr 15, 2021

Emmmmm... 为什么会有这种需求呢?

@sunsang
Copy link
Author

sunsang commented Apr 15, 2021

看了一下源码,是在第一次回调后,就从 responseCallbacks 数组删除了这个回调,导致第二次回调找不到回调的方法。
请问可以把这行放开吗? 会有什么问题,或者有更好的方案

image

@Lision
Copy link
Owner

Lision commented Apr 15, 2021

  • 理论上 js 的回调执行之后,js 完全可以自己定时调用 func;
  • 如果 js 多次执行,我理解 1 对 1 的调用和回调也可以满足。
    以上,所以我不太清楚哪些场景会产生这种需求。

@sunsang
Copy link
Author

sunsang commented Apr 15, 2021

Emmmmm... 为什么会有这种需求呢?

比如两个回调的状态不一样,可能第一次回调是complate的状态,第二次回调是success的状态

@Lision
Copy link
Owner

Lision commented Apr 15, 2021

我理解你的需求类似于一个 stream 的形式,你需要 subscribe 另一方的执行状态,本质上是一个观察者模式?
如果我的理解没错的话,感觉是不是可以让 native 在执行状态变化的时候主动调用 js 代码来通知到 js 呢?

@sunsang
Copy link
Author

sunsang commented Apr 15, 2021

我理解你的需求类似于一个 stream 的形式,你需要 subscribe 另一方的执行状态,本质上是一个观察者模式?
如果我的理解没错的话,感觉是不是可以让 native 在执行状态变化的时候主动调用 js 代码来通知到 js 呢?

@sunsang sunsang closed this as completed Apr 15, 2021
@sunsang sunsang reopened this Apr 15, 2021
@sunsang
Copy link
Author

sunsang commented Apr 15, 2021

我理解你的需求类似于一个 stream 的形式,你需要 subscribe 另一方的执行状态,本质上是一个观察者模式?
如果我的理解没错的话,感觉是不是可以让 native 在执行状态变化的时候主动调用 js 代码来通知到 js 呢?

差不多是这个意思,可以像你说的这样。就是看有没有更好的方案,想利用这个callBack这个回调不知道行不行?删除那一行,会有问题吗?

@Lision
Copy link
Owner

Lision commented Apr 15, 2021

会导致存放回调的数据结构积累越来越多的回调 block。

@Lision Lision closed this as completed Apr 16, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants