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
680
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
110
BluetoothDevice.getName()に裏切られた話
lvla
0
140
Jetpack Composeで画像クロップ機能を実装する
lvla
0
760
Jetpack Compose drag gesture and pinch gesture
lvla
1
2.3k
Jetpack Compose Layout API
lvla
1
540
BLEを使ったアプリを継続的に開発するために
lvla
0
810
RecyclerView.ItemAnimator
lvla
1
250
RecycledViewPool
lvla
1
120
CameraX
lvla
2
2.2k
Other Decks in Technology
See All in Technology
LangSmith入門―トレース/評価/プロンプト管理などを担うLLMアプリ開発プラットフォーム
os1ma
5
790
20分で完全に理解するGrafanaダッシュボード
hamadakoji
5
1k
コードファーストの考え方。 Amplify Gen2から学ぶAWS次世代のWeb開発体験
yoshiitaka
2
540
AWS アーキテクチャ作図入門/aws-architecture-diagram-101
ma2shita
16
6.6k
Azureの基本的な権限管理の勉強会
yhana
1
2.2k
NewSQL Landscape
oracle4engineer
PRO
2
2.7k
M5stackで使用できるpHセンサの開発
shinrinakamura
1
290
自己改善からチームを動かす! 「セルフエンジニアリングマネージャー」のすゝめ
shoota
6
1.1k
AWS学習者向けにAzureの解説スライドを作成した話
handy
3
220
Building Dashboards as a Hobby
egmc
0
430
個人のAWSアカウントをマルチ運用してみた
miura55
2
260
認知症フレンドリーテックとスタックチャン
naokiuc
0
380
Featured
See All Featured
GraphQLとの向き合い方2022年版
quramy
33
12k
Automating Front-end Workflow
addyosmani
1357
200k
Building an army of robots
kneath
300
41k
Being A Developer After 40
akosma
67
580k
GitHub's CSS Performance
jonrohan
1025
450k
Scaling GitHub
holman
457
140k
Adopting Sorbet at Scale
ufuk
69
8.6k
Ruby is Unlike a Banana
tanoku
96
10k
VelocityConf: Rendering Performance Case Studies
addyosmani
321
23k
Making the Leap to Tech Lead
cromwellryan
125
8.5k
The World Runs on Bad Software
bkeepers
PRO
61
6.7k
The Power of CSS Pseudo Elements
geoffreycrofte
62
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