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
710
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
99
graphicsLayer
lvla
0
210
BluetoothDevice.getName()に裏切られた話
lvla
0
350
Jetpack Composeで画像クロップ機能を実装する
lvla
0
1.2k
Jetpack Compose drag gesture and pinch gesture
lvla
1
3.9k
Jetpack Compose Layout API
lvla
1
660
BLEを使ったアプリを継続的に開発するために
lvla
0
1k
RecyclerView.ItemAnimator
lvla
1
320
RecycledViewPool
lvla
1
220
Other Decks in Technology
See All in Technology
R-SCoRe: Revisiting Scene Coordinate Regression for Robust Large-Scale Visual Localization
takmin
0
430
JOAI発表資料 @ 関東kaggler会
joai_committee
1
250
ドキュメントはAIの味方!スタートアップのアジャイルを加速するADR
kawauso
3
310
夢の印税生活 / Life on Royalties
tmtms
0
280
アジャイルテストで高品質のスプリントレビューを
takesection
0
110
kintone開発チームの紹介
cybozuinsideout
PRO
0
73k
GCASアップデート(202506-202508)
techniczna
0
250
AIが住民向けコンシェルジュに?Amazon Connectと生成AIで実現する自治体AIエージェント!
yuyeah
0
260
AIドリブンのソフトウェア開発 - うまいやり方とまずいやり方
okdt
PRO
9
560
いま、あらためて考えてみるアカウント管理 with IaC / Account management with IaC
kohbis
2
680
帳票Vibe Coding
terurou
0
140
どこで動かすか、誰が動かすか 〜 kintoneのインフラ基盤刷新と運用体制のシフト 〜
ueokande
0
180
Featured
See All Featured
Why Our Code Smells
bkeepers
PRO
338
57k
Done Done
chrislema
185
16k
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
139
34k
The Cost Of JavaScript in 2023
addyosmani
53
8.8k
Building an army of robots
kneath
306
46k
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
34
3.1k
How to Ace a Technical Interview
jacobian
279
23k
Building Better People: How to give real-time feedback that sticks.
wjessup
367
19k
Fantastic passwords and where to find them - at NoRuKo
philnash
51
3.4k
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
32
1.4k
4 Signs Your Business is Dying
shpigford
184
22k
Building a Modern Day E-commerce SEO Strategy
aleyda
43
7.5k
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