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
750
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
140
graphicsLayer
lvla
0
250
BluetoothDevice.getName()に裏切られた話
lvla
0
390
Jetpack Composeで画像クロップ機能を実装する
lvla
0
1.2k
Jetpack Compose drag gesture and pinch gesture
lvla
1
4.2k
Jetpack Compose Layout API
lvla
1
690
BLEを使ったアプリを継続的に開発するために
lvla
0
1.1k
RecyclerView.ItemAnimator
lvla
1
350
RecycledViewPool
lvla
1
260
Other Decks in Technology
See All in Technology
Oracle Database@AWS:サービス概要のご紹介
oracle4engineer
PRO
4
1.5k
AWS CDK の目玉新機能「Mixins」とは / cdk-mixins
gotok365
2
240
Oracle Base Database Service 技術詳細
oracle4engineer
PRO
15
94k
競争優位を生み出す戦略的内製開発の実践技法
masuda220
PRO
2
380
インシデント対応入門
grimoh
7
5.1k
Amazon Bedrock AgentCoreでブラウザ拡張型AI調査エージェントを開発した話 (シングルエージェント編)
nasuvitz
2
110
全自動で回せ!Claude Codeマーケットプレイス運用術
yukyu30
3
120
1 年間の育休から時短勤務で復帰した私が、 AI を駆使して立ち上がりを早めた話
lycorptech_jp
PRO
0
140
AIで「ふとした疑問」を即座に検証する 〜定量で圧倒するN1理解〜
kakehashi
PRO
3
720
Getting started with Google Antigravity
meteatamel
0
350
Agent Payments Protocolで実装するAIエージェント間取引
tokio007
0
160
フルスタックGoでスコア改ざんを防いだ話
ponyo877
0
510
Featured
See All Featured
Kristin Tynski - Automating Marketing Tasks With AI
techseoconnect
PRO
0
170
Odyssey Design
rkendrick25
PRO
2
520
Faster Mobile Websites
deanohume
310
31k
What's in a price? How to price your products and services
michaelherold
247
13k
Balancing Empowerment & Direction
lara
5
920
sira's awesome portfolio website redesign presentation
elsirapls
0
160
BBQ
matthewcrist
89
10k
A Tale of Four Properties
chriscoyier
162
24k
ReactJS: Keep Simple. Everything can be a component!
pedronauck
666
130k
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
38
2.7k
Automating Front-end Workflow
addyosmani
1371
200k
Building a Scalable Design System with Sketch
lauravandoore
463
34k
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