rxbus

public class RxBus {post

private static final RxBus INSTANCE = new RxBus();

private final Subject<Object, Object> mBusSubject = new SerializedSubject<>(PublishSubject.create());

public static RxBus getInstance() {
    return INSTANCE;
}

public <T> Subscription register(final Class<T> eventClass, Action1<T> onNext) {
    return mBusSubject
            .filter(event -> event.getClass().equals(eventClass))
            .map(obj -> (T) obj)
            .subscribe(onNext);
}

public void post(Object event) {
    mBusSubject.onNext(event);
}

}code

相關文章
相關標籤/搜索