Giter Site home page Giter Site logo

Comments (1)

luckybilly avatar luckybilly commented on May 18, 2024

@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)注销动态组件

from cc.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.