Change sample ViewHolders to implement LifecycleScopeProvider#157
Merged
ZacSweers merged 2 commits intouber:masterfrom Jan 8, 2018
Merged
Change sample ViewHolders to implement LifecycleScopeProvider#157ZacSweers merged 2 commits intouber:masterfrom
ZacSweers merged 2 commits intouber:masterfrom
Conversation
ZacSweers
reviewed
Jan 4, 2018
Collaborator
ZacSweers
left a comment
There was a problem hiding this comment.
Looks good. Just a few nits and looks like you'll need to sign the CLA from your github account
| case BIND: | ||
| return ViewHolderEvent.UNBIND; | ||
| default: | ||
| throw new LifecycleEndedException("Cannot use view holder lifecycle after unbind."); |
| } | ||
|
|
||
| override fun peekLifecycle(): ViewHolderEvent? { | ||
| return lifecycleEvents.value |
Collaborator
There was a problem hiding this comment.
nit: can be single body expression
override fun peekLifecycle() = lifecycleEvents.value| } | ||
| } | ||
| override fun lifecycle(): Observable<ViewHolderEvent> { | ||
| return lifecycleEvents.hide() |
Collaborator
There was a problem hiding this comment.
nit: can be single body expression
override fun lifecycle() = lifecycleEvents.hide()| override fun onUnbind() { | ||
| emitUnbindIfPresent() | ||
| unbindNotifier = null | ||
| lifecycleEvents.onNext(UNBIND) |
Collaborator
There was a problem hiding this comment.
can single body this and onBind above as well
| : BindAwareViewHolder(itemView), LifecycleScopeProvider<AutoDisposeViewHolderKotlin.ViewHolderEvent> { | ||
|
|
||
| private var unbindNotifier: MaybeSubject<Any>? = null | ||
| private val lifecycleEvents = BehaviorSubject.create<ViewHolderEvent>() |
Collaborator
There was a problem hiding this comment.
let's make this lazy
private val lifecycleEvents by lazy { BehaviorSubject.create<ViewHolderEvent>() }
Closed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description:
Change AutoDisposeViewHolder from a ScopeProvider to a LifecycleScopeProvider. This better matches the underlying programming model, and provides some safety guarantees around subscription timing, as well as helping to detect certain issues that may arise from support library version bumps and changes to internal RecyclerView/ViewHolder logic.