-
Notifications
You must be signed in to change notification settings - Fork 906
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Expose ribActionEvents stream #599
Changes from 2 commits
8587e79
66eac33
5ff4748
26fe506
3ab3955
18ced24
80c5846
38ae582
546ac78
062b002
747b831
5a42204
7009b81
2edee91
7f251b1
8201984
2a5db8e
3e7983a
ee3aff2
59014ba
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,12 +33,24 @@ public object RibEvents { | |
@JvmStatic | ||
public val ribActionEvents: Observable<RibActionInfo> = mutableRibDurationEvents.asObservable() | ||
|
||
private var areRibActionEmissionsAllowed = false | ||
|
||
/** | ||
* To be called before start observing/collecting on [ribActionEvents] (usually at your earliest | ||
* application point) | ||
*/ | ||
@JvmStatic | ||
public fun allowRibActionEmissions() { | ||
this.areRibActionEmissionsAllowed = true | ||
} | ||
|
||
/** | ||
* @param eventType [RibEventType] | ||
* @param child [Router] | ||
* @param parent [Router] and null for the root ribs that are directly attached to | ||
* RibActivity/Fragment | ||
*/ | ||
@JvmStatic | ||
public fun emitRouterEvent(eventType: RibEventType, child: Router<*>, parent: Router<*>?) { | ||
psteiger marked this conversation as resolved.
Show resolved
Hide resolved
FranAguilera marked this conversation as resolved.
Show resolved
Hide resolved
|
||
mutableRouterEvents.tryEmit(RibRouterEvent(eventType, child, parent)) | ||
} | ||
|
@@ -48,39 +60,48 @@ public object RibEvents { | |
* for each RIB component. | ||
* | ||
* @param ribAction The related RIB action type. e.g. didBecomeActive, willLoad, etc | ||
* @param ribCallerClassType Related RIB component class type | ||
* @param ribComponent Related RIB component | ||
* @param ribComponentType The RIB component type (e.g. Interactor, Router, Presenter, Worker) | ||
* @param ribEventType RIB event type (e.g. ATTACH/DETACH) | ||
*/ | ||
internal inline fun <T : Any> triggerRibActionAndEmitEvents( | ||
ribCallerClassType: T, | ||
internal inline fun triggerRibActionAndEmitEvents( | ||
ribComponent: RibComponent, | ||
ribComponentType: RibComponentType, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would like to specify a property on the new RibComponent to be overriden, unfortunately given that Worker and RibCoroutineWorker are interfaces we cannot restrict visibility of those |
||
ribEventType: RibEventType, | ||
ribAction: () -> Unit, | ||
) { | ||
val ribClassName = ribCallerClassType.asQualifiedName() | ||
ribClassName?.emitRibEventAction(ribComponentType, ribEventType, RibActionState.STARTED) | ||
emitRibEventActionIfNeeded(ribComponent, ribComponentType, ribEventType, RibActionState.STARTED) | ||
ribAction() | ||
ribClassName?.emitRibEventAction(ribComponentType, ribEventType, RibActionState.COMPLETED) | ||
emitRibEventActionIfNeeded( | ||
ribComponent, | ||
ribComponentType, | ||
ribEventType, | ||
RibActionState.COMPLETED, | ||
) | ||
} | ||
|
||
private fun Any.asQualifiedName(): String? = javaClass.kotlin.qualifiedName | ||
|
||
/** | ||
* Emits emission of ATTACHED/DETACHED events for each RIB component. | ||
* | ||
* @param ribComponentType The RIB component type (e.g. Interactor, Router, Presenter) | ||
* @param ribEventType RIB event type (e.g. ATTACH/DETACH) | ||
* @param ribActionState: RibActionType, | ||
*/ | ||
private fun String.emitRibEventAction( | ||
private fun emitRibEventActionIfNeeded( | ||
ribComponent: RibComponent, | ||
ribComponentType: RibComponentType, | ||
ribEventType: RibEventType, | ||
ribActionState: RibActionState, | ||
) { | ||
if (!areRibActionEmissionsAllowed) { | ||
// Unless specified explicitly via [RibEvents.allowRibActionEmissions] there is no need | ||
// to create unnecessary objects if no one is observing/collecting RibAction events | ||
return | ||
} | ||
|
||
val ribActionInfo = | ||
RibActionInfo( | ||
this, | ||
ribComponent.javaClass.name, | ||
ribComponentType, | ||
ribEventType, | ||
ribActionState, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,7 +34,7 @@ protected constructor( | |
public open val interactor: I, | ||
private val ribRefWatcher: RibRefWatcher, | ||
private val mainThread: Thread, | ||
) { | ||
) : RibComponent { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Probably too generic for a name for this set of callbacks. How about something more explicit around emitting callbacks around lifecycles, like RibEventEmitter? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good idea, I like this better There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Decided to go with |
||
private val children: MutableList<Router<*>> = CopyOnWriteArrayList() | ||
private val interactorGeneric: Interactor<*, *> | ||
get() = interactor as Interactor<*, *> | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Coroutine Worker? Why reserve for next release?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We may need to tweak a bit more RibCoroutine worker in order to provide accurate monitoring as mentioned by @psteiger earlier
Given there are barely any users internally of RibCoroutineWorker, I'm not concerned to leave these changes to be implemented on a separate PR