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

AndroidEventBus的优化建议 #48

Open
xiaweicheng opened this issue Jan 13, 2017 · 1 comment
Open

AndroidEventBus的优化建议 #48

xiaweicheng opened this issue Jan 13, 2017 · 1 comment

Comments

@xiaweicheng
Copy link

(1)EventBus里面的handleStickyEvent方法最后执行的判断条件冗余,因为通过foundEventType找到的subscription其eventType一定和foundType相等。所以判断条件只需要isTarget(subItem, subscriber)即可

(2)经过第一步之后,Subscription里面的EventType就没有被用到,可以去掉了。因为EventType在mSubscribeMap是Key的角色,Subscription本质是value的角色,value里面含有key很奇怪

(3)TargetMethod这个类,感觉有点冗余,这个类只在SubscribeMethodHunter里面使用,它从findSubcribeMethods(...)方法里面接收Method , EventType type, ThreadMode 参数,然后传递给subscibe(EventType event, TargetMethod method, Object subscriber)使用,建议把subscribe(...)方法改成 private void subscibe(EventType event, Object subscriber, Method method, ThreadMode threadMode) ,这样TargetMethod这个类也可以优化掉。

@xiaweicheng
Copy link
Author

(4)Subscription的equals()方法在用到了subscriber.get().equals(other.subscriber.get())。这样会导致两个值相等的不同对象,无法同时注册。建议把调用 subscriber.get().equals(other.subscriber.get()) 的地方subscriber.get() == other.subscriber.get()

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

1 participant