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

请问CC支持多次回调么? #58

Closed
SheepYang1993 opened this issue Sep 18, 2018 · 1 comment
Closed

请问CC支持多次回调么? #58

SheepYang1993 opened this issue Sep 18, 2018 · 1 comment

Comments

@SheepYang1993
Copy link

例如文件下载进度回调,需要多次回调。

@luckybilly
Copy link
Owner

@SheepYang1993 CC是一对一的通信,不支持多次回调。
但可以使用动态组件来实现此类功能,实现步骤如下:

  1. DownloadComponent中定义2个actionName: “subscribe”和“unsubscribe”,接收订阅下载状态的组件
  2. Activity/Fragment在需要监听下载状态时创建一个IDynamicComponent实现类,通过CC.registerComponent(component)动态注册,
  3. 通过CC调用DownloadComponent的subscribe向下载组件注册监听
  4. DownloadComponent内部记录所有注册监听的组件componentName和actionName
  5. DownloadComponent下载状态改变时,将通过CC调用所有注册监听的组件将下载状态发送给它们
  6. Activity/Fragment不再需要监听下载状态时(如:onDestroy)通过CC调用DownloadComponent的unsubscribe进行注销,
  7. 调用CC.unregisterComponent(component)注销动态组件

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