Skip to content

Commit

Permalink
adjusting failurereaction
Browse files Browse the repository at this point in the history
  • Loading branch information
ptmr3 committed May 13, 2022
1 parent 90db48b commit 97ad06f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
18 changes: 11 additions & 7 deletions src/main/java/com/ptmr3/fluxx/Fluxx.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import java.util.concurrent.ConcurrentHashMap
class Fluxx {
private val mActionSubscribers = ConcurrentHashMap<Any, Set<Method>>()
private val mReactionSubscribers = ConcurrentHashMap<Any, Set<Method>>()
private val mFailureReactionSubscribers = ConcurrentHashMap<Any, Set<Method>>()

fun getActionSubscriberMethods(action: FluxxAction): Observable<HashMap<String, Any>> {
return Observable.create { observableEmitter ->
Expand Down Expand Up @@ -48,15 +49,15 @@ class Fluxx {
}
}

fun getFailureReactionSubscriberMethods(reaction: FluxxFailureReaction): Observable<HashMap<String, Any>> {
fun getFailureReactionSubscriberMethods(failureReaction: FluxxFailureReaction): Observable<HashMap<String, Any>> {
return Observable.create { observableEmitter ->
mReactionSubscribers.keys.map { parentClass ->
mReactionSubscribers[parentClass].orEmpty().map {
if (reaction.type == it.getAnnotation(FailureReaction::class.java).reactionType) {
mFailureReactionSubscribers.keys.map { parentClass ->
mFailureReactionSubscribers[parentClass].orEmpty().map {
if (failureReaction.type == it.getAnnotation(FailureReaction::class.java).failureReactionType) {
val map = HashMap<String, Any>()
map[METHOD] = it
map[CLASS] = parentClass
map[FAILURE_REACTION] = reaction
map[FAILURE_REACTION] = failureReaction
observableEmitter.onNext(map)
}
}
Expand Down Expand Up @@ -96,14 +97,14 @@ class Fluxx {

private fun methodsWithFailureReactionAnnotation(parentClass: Any): Completable {
return Completable.fromAction {
if (!mReactionSubscribers.containsKey(parentClass)) {
if (!mFailureReactionSubscribers.containsKey(parentClass)) {
val classMethods = HashSet<Method>()
parentClass.javaClass.declaredMethods.map {
if (it.isAnnotationPresent(FailureReaction::class.java)) {
classMethods.add(it)
}
}
mReactionSubscribers[parentClass] = classMethods
mFailureReactionSubscribers[parentClass] = classMethods
}
}
}
Expand All @@ -123,6 +124,9 @@ class Fluxx {
if (mReactionSubscribers.containsKey(view)) {
mReactionSubscribers.remove(view)
}
if (mFailureReactionSubscribers.contains(view)) {
mFailureReactionSubscribers.remove(view)
}
}

companion object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ import kotlin.annotation.AnnotationTarget.*

@Retention(RUNTIME)
@Target(FUNCTION, PROPERTY_GETTER, PROPERTY_SETTER)
annotation class FailureReaction(val reactionType: String)
annotation class FailureReaction(val failureReactionType: String)

0 comments on commit 97ad06f

Please sign in to comment.