Skip to content

实现方式挺好的,不过发送事件的调用方式在语义上不好理解,…… #2

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

Open
liyujiang-gzu opened this issue Dec 2, 2016 · 3 comments

Comments

@liyujiang-gzu
Copy link

实现方式挺好的,不过发送事件的调用方式在语义上不好理解,能否将“”EventBus.get(...).onXXX(...)“”重构为“”EventBus.obtain(...).sendToTarget()“”更容易理解,类似于安卓sdk的Handler&Message那样

@liyujiang-gzu
Copy link
Author

可考虑充分利用泛型和反射来实现

@LuckyJayce
Copy link
Owner

EventBus.get(...).onXXX(...)
get 是get到Event的代理类
后面onXXX是自定的event的方法,属于你自己的不一定用on开头

@liyujiang-gzu
Copy link
Author

这倒也是。
我猜想的重构思路如下,不知是否可行:
1、定义一个继承自IEvent的抽象类MessageEvent,里面包含一个final的obtainMessage方法及一个抽象的onMessageReceived方法。
2、额外添加一个Message类作为EventBus.get的通用参数,里面定义两个属性what及obj,以及一个final的sendToTarget方法。
3、sendToTarget里通过Proxy实现onMessageReceived的调用。

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