我刚刚观看了 Jake Wharton The State of Managing State with RxJava的会议。
他建议以这种方式将事件从视图转换为动作:
Observable<Event> events = RxView.clicks(view).map(__ -> new Event());
ObservableTransformer<Event, Action> action = events -> events.flatMap(/* ... */);
events.compose(action).subscribe();
我想知道这种实现的不同之处:
Observable<Event> events = RxView.clicks(view).map(__ -> new Event());
Observable<Action> action = events.flatMap(/* ... */);
action.subscribe();
将
compose()
与flatMap()
一起使用有什么区别 ObservableTransformer和一个简单- name: Drop/delete mysql table {{ mysql_table }} shell: mysqladmin -h 127.0.0.1 -p{{ mysql_password }} -u{{ mysql_user }} drop {{ mysql_table }} -f # If it fails it means db was already deleted, so continue. ignore_errors: True tags: - mysql - mysql_rebuild_db - mysql_rebuild_db_quick - name: Add mysql table {{ mysql_table }} shell: mysqladmin -h 127.0.0.1 -p{{ mysql_password }} -u{{ mysql_user }} create {{ mysql_table }} -f tags: - mysql - mysql_rebuild_db - mysql_rebuild_db_quick - name: Create mysql user {{ mysql_user }} in {{ mysql_table }} shell: echo "CREATE USER {{ mysql_user }}@'localhost' IDENTIFIED BY '{{ mysql_password }}';" | mysql -h 127.0.0.1 -proot -uroot # The user may already exists in a previous run ignore_errors: True tags: - mysql - mysql_rebuild_db - mysql_rebuild_db_quick
有两个 可观察到的?
答案 0 :(得分:12)
Daniel Lew对这些差异有一个很好的解释。简而言之:
不同之处在于compose()是更高级别的抽象:它 在整个流上运行,而不是单独发出的物品。
有关详细信息,请查看this article中的完整说明(在名为关于flatMap()的部分?)