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
Sponsored
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
Moyuru Aizawa
June 12, 2017
Technology
1
740
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
130
graphicsLayer
lvla
0
240
BluetoothDevice.getName()に裏切られた話
lvla
0
390
Jetpack Composeで画像クロップ機能を実装する
lvla
0
1.2k
Jetpack Compose drag gesture and pinch gesture
lvla
1
4.1k
Jetpack Compose Layout API
lvla
1
690
BLEを使ったアプリを継続的に開発するために
lvla
0
1.1k
RecyclerView.ItemAnimator
lvla
1
340
RecycledViewPool
lvla
1
260
Other Decks in Technology
See All in Technology
Sansan Engineering Unit 紹介資料
sansan33
PRO
1
3.8k
ClickHouseはどのように大規模データを活用したAIエージェントを全社展開しているのか
mikimatsumoto
0
200
顧客の言葉を、そのまま信じない勇気
yamatai1212
1
340
茨城の思い出を振り返る ~CDKのセキュリティを添えて~ / 20260201 Mitsutoshi Matsuo
shift_evolve
PRO
1
200
Context Engineeringが企業で不可欠になる理由
hirosatogamo
PRO
3
440
Cosmos World Foundation Model Platform for Physical AI
takmin
0
430
あたらしい上流工程の形。 0日導入からはじめるAI駆動PM
kumaiu
5
760
生成AI時代にこそ求められるSRE / SRE for Gen AI era
ymotongpoo
5
2.8k
Context Engineeringの取り組み
nutslove
0
290
入社1ヶ月でデータパイプライン講座を作った話
waiwai2111
1
250
Tebiki Engineering Team Deck
tebiki
0
24k
SREが向き合う大規模リアーキテクチャ 〜信頼性とアジリティの両立〜
zepprix
0
410
Featured
See All Featured
Pawsitive SEO: Lessons from My Dog (and Many Mistakes) on Thriving as a Consultant in the Age of AI
davidcarrasco
0
62
Thoughts on Productivity
jonyablonski
74
5k
Making the Leap to Tech Lead
cromwellryan
135
9.7k
How to audit for AI Accessibility on your Front & Back End
davetheseo
0
180
The B2B funnel & how to create a winning content strategy
katarinadahlin
PRO
0
270
Large-scale JavaScript Application Architecture
addyosmani
515
110k
HU Berlin: Industrial-Strength Natural Language Processing with spaCy and Prodigy
inesmontani
PRO
0
200
Navigating the moral maze — ethical principles for Al-driven product design
skipperchong
2
240
Bioeconomy Workshop: Dr. Julius Ecuru, Opportunities for a Bioeconomy in West Africa
akademiya2063
PRO
1
54
KATA
mclloyd
PRO
34
15k
Tips & Tricks on How to Get Your First Job In Tech
honzajavorek
0
430
WENDY [Excerpt]
tessaabrams
9
36k
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