Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
AutoDispose
Search
Moyuru Aizawa
June 12, 2017
Technology
1
700
AutoDispose
Rx Ja Night #2
TwitterID変えました。@lvla0805 -> @MoyuruAizawa
Moyuru Aizawa
June 12, 2017
Tweet
Share
More Decks by Moyuru Aizawa
See All by Moyuru Aizawa
graphicsLayer
lvla
0
150
BluetoothDevice.getName()に裏切られた話
lvla
0
210
Jetpack Composeで画像クロップ機能を実装する
lvla
0
870
Jetpack Compose drag gesture and pinch gesture
lvla
1
2.9k
Jetpack Compose Layout API
lvla
1
580
BLEを使ったアプリを継続的に開発するために
lvla
0
870
RecyclerView.ItemAnimator
lvla
1
280
RecycledViewPool
lvla
1
150
CameraX
lvla
2
2.2k
Other Decks in Technology
See All in Technology
PdMはどのように全てのスピードを上げられるか ~ 非連続進化のための具体的な取り組み ~
sansantech
PRO
2
510
Javaにおける関数型プログラミンへの取り組み
skrb
7
310
プロダクトエンジニアを支えるための開発生産性向上施策
tsukakei
0
140
2024年のナビゲーション・フォーカス対応:Composeでキーボード・ナビゲーションをサポートしよう
tahia910
0
100
自社サービスのための独自リリース版Redmine「RedMica」の取り組み
vividtone
0
1.1k
セキュリティ監視の内製化 効率とリスク
mixi_engineers
PRO
7
910
「認証認可」という体験をデザインする ~Nekko Cloud認証認可基盤計画
logica0419
2
250
Tricentisにおけるテスト自動化へのAI活用ご紹介/20240910Shunsuke Katakura
shift_evolve
0
180
リアルお遍路+SORACOM IoT
ozk009
1
120
より快適なエラーログ監視を目指して
leveragestech
4
1.3k
Segment Anything Model 2
tenten0727
3
620
スタッフエンジニアの道: The Staff Engineer’s Path
snoozer05
PRO
41
13k
Featured
See All Featured
How To Stay Up To Date on Web Technology
chriscoyier
786
250k
Raft: Consensus for Rubyists
vanstee
135
6.5k
Designing Dashboards & Data Visualisations in Web Apps
destraynor
227
52k
How GitHub Uses GitHub to Build GitHub
holman
472
290k
What’s in a name? Adding method to the madness
productmarketing
PRO
21
3k
How to Think Like a Performance Engineer
csswizardry
16
950
No one is an island. Learnings from fostering a developers community.
thoeni
18
2.9k
Building Flexible Design Systems
yeseniaperezcruz
325
37k
WebSockets: Embracing the real-time Web
robhawkes
59
7.3k
Navigating Team Friction
lara
183
13k
Keith and Marios Guide to Fast Websites
keithpitt
408
22k
Happy Clients
brianwarren
96
6.6k
Transcript
AutoDispose @lvla0805
lvla Ѫᖒ๖ (Moyuru Aizawa) - Kotlin engineer at CyberAgent, Inc.
- FRESH! lvla0805
override fun onCreate(…) { … Flowable.interval(1, TimeUnit.SECONDS) .subscribe { sec
-> textView.text = "${sec}s" } } Disposable
var disposable: Disposable? = null override fun onCreate(…) {
… disposable = Flowable.interval(1, TimeUnit.SECONDS) .subscribe { sec -> textView.text = "${sec}s" } } override fun onDestroy() { disposable?.dispose() } Disposable
val disposables = CompositeDisposable() override fun onCreate(…) { …
Flowable.interval(1, TimeUnit.SECONDS) .subscribe { sec -> textView.text = "${sec}s" } .addTo(disposables) } override fun onDestroy() { disposables.dispose() super.onDestroy() } CompositeDisposable
AutoDispose
override fun onCreate(…) { … Flowable.interval(1, TimeUnit.SECONDS) .to(FlowableScoper<Long>(this)) .subscribe {
sec -> textView.text = "${sec}s" } } AutoDispose
enum class ActivityLifeCycle { CREATE, …, DESTROY } AutoDispose
public interface LifecycleScopeProvider<E> { Observable<E> lifecycle(); Function<E, E> correspondingEvents(); E
peekLifecycle(); } AutoDispose
abstract class RxActivity : AppCompatActivity(), LifecycleScopeProvider<ActivityLifeCycle> { … } AutoDispose
‣ lifecycle() ‣ returns an Observable of lifecycle events. ‣
This should be backed by a BehaviorSubject or something similar ‣ correspondingEvents() ‣ a mapping of events to corresponding ones. ‣ i.e. CREATE -> DESTROY ‣ peekLifecycle() ‣ returns the current lifecycle state of the object. AutoDispose
abstract class RxActivity : AppCompatActivity(), LifecycleScopeProvider<ActivityLifeCycle> { private val
lifecycle = BehaviorSubject.create<ActivityLifeCycle>() private lateinit var currentEvent: ActivityLifeCycle override fun lifecycle(): Observable<ActivityLifeCycle> = lifecycle override fun correspondingEvents(): Function<ActivityLifeCycle, ActivityLifeCycle> { return Function { lastEvent: ActivityLifeCycle -> when (lastEvent) { CREATE -> DESTROY else -> throw OutsideLifecycleException("Activity was destroyed") } } } override fun peekLifecycle() = currentEvent } AutoDispose
class MainActivity : RxActivity() { … override fun onCreate(…) {
Flowable.interval(1, TimeUnit.SECONDS) .to(FlowableScoper<Long>(this)) .subscribe { sec -> textView.text = "${sec}s" } } } AutoDispose
Thank you