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
BLUETOOTH_SCAN and iBeacon
lvla
1
56
graphicsLayer
lvla
0
180
BluetoothDevice.getName()に裏切られた話
lvla
0
290
Jetpack Composeで画像クロップ機能を実装する
lvla
0
1k
Jetpack Compose drag gesture and pinch gesture
lvla
1
3.4k
Jetpack Compose Layout API
lvla
1
620
BLEを使ったアプリを継続的に開発するために
lvla
0
950
RecyclerView.ItemAnimator
lvla
1
290
RecycledViewPool
lvla
1
180
Other Decks in Technology
See All in Technology
エンジニアのためのドキュメント力基礎講座〜構造化思考から始めよう〜(2025/02/15jbug広島#15発表資料)
yasuoyasuo
17
6.8k
インフラをつくるとはどういうことなのか、 あるいはPlatform Engineeringについて
nwiizo
5
2.6k
PHPカンファレンス名古屋-テックリードの経験から学んだ設計の教訓
hayatokudou
2
310
リアルタイム分析データベースで実現する SQLベースのオブザーバビリティ
mikimatsumoto
0
1.4k
地方拠点で エンジニアリングマネージャーってできるの? 〜地方という制約を楽しむオーナーシップとコミュニティ作り〜
1coin
1
230
RECRUIT TECH CONFERENCE 2025 プレイベント【高橋】
recruitengineers
PRO
0
160
Developer Summit 2025 [14-D-1] Yuki Hattori
yuhattor
19
6.2k
ハッキングの世界に迫る~攻撃者の思考で考えるセキュリティ~
nomizone
13
5.2k
Oracle Cloud Infrastructure:2025年2月度サービス・アップデート
oracle4engineer
PRO
1
210
バックエンドエンジニアのためのフロントエンド入門 #devsumiC
panda_program
18
7.5k
Developers Summit 2025 浅野卓也(13-B-7 LegalOn Technologies)
legalontechnologies
PRO
0
720
PHPで印刷所に入稿できる名札データを作る / Generating Print-Ready Name Tag Data with PHP
tomzoh
0
110
Featured
See All Featured
RailsConf 2023
tenderlove
29
1k
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
29
1k
It's Worth the Effort
3n
184
28k
Visualization
eitanlees
146
15k
Building a Scalable Design System with Sketch
lauravandoore
461
33k
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
193
16k
Git: the NoSQL Database
bkeepers
PRO
427
64k
The Illustrated Children's Guide to Kubernetes
chrisshort
48
49k
Intergalactic Javascript Robots from Outer Space
tanoku
270
27k
Faster Mobile Websites
deanohume
306
31k
Large-scale JavaScript Application Architecture
addyosmani
511
110k
The Language of Interfaces
destraynor
156
24k
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