From 97ad06faecbec43806a0e2b3dcea2576e810fd63 Mon Sep 17 00:00:00 2001 From: ptmr3 Date: Fri, 13 May 2022 16:33:16 -0400 Subject: [PATCH] adjusting failurereaction --- src/main/java/com/ptmr3/fluxx/Fluxx.kt | 18 +++++++++++------- .../ptmr3/fluxx/annotation/FailureReaction.kt | 2 +- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/ptmr3/fluxx/Fluxx.kt b/src/main/java/com/ptmr3/fluxx/Fluxx.kt index 7b19364..bec4d5c 100644 --- a/src/main/java/com/ptmr3/fluxx/Fluxx.kt +++ b/src/main/java/com/ptmr3/fluxx/Fluxx.kt @@ -13,6 +13,7 @@ import java.util.concurrent.ConcurrentHashMap class Fluxx { private val mActionSubscribers = ConcurrentHashMap>() private val mReactionSubscribers = ConcurrentHashMap>() + private val mFailureReactionSubscribers = ConcurrentHashMap>() fun getActionSubscriberMethods(action: FluxxAction): Observable> { return Observable.create { observableEmitter -> @@ -48,15 +49,15 @@ class Fluxx { } } - fun getFailureReactionSubscriberMethods(reaction: FluxxFailureReaction): Observable> { + fun getFailureReactionSubscriberMethods(failureReaction: FluxxFailureReaction): Observable> { 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() map[METHOD] = it map[CLASS] = parentClass - map[FAILURE_REACTION] = reaction + map[FAILURE_REACTION] = failureReaction observableEmitter.onNext(map) } } @@ -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() parentClass.javaClass.declaredMethods.map { if (it.isAnnotationPresent(FailureReaction::class.java)) { classMethods.add(it) } } - mReactionSubscribers[parentClass] = classMethods + mFailureReactionSubscribers[parentClass] = classMethods } } } @@ -123,6 +124,9 @@ class Fluxx { if (mReactionSubscribers.containsKey(view)) { mReactionSubscribers.remove(view) } + if (mFailureReactionSubscribers.contains(view)) { + mFailureReactionSubscribers.remove(view) + } } companion object { diff --git a/src/main/java/com/ptmr3/fluxx/annotation/FailureReaction.kt b/src/main/java/com/ptmr3/fluxx/annotation/FailureReaction.kt index 79ffb41..e605a14 100644 --- a/src/main/java/com/ptmr3/fluxx/annotation/FailureReaction.kt +++ b/src/main/java/com/ptmr3/fluxx/annotation/FailureReaction.kt @@ -5,4 +5,4 @@ import kotlin.annotation.AnnotationTarget.* @Retention(RUNTIME) @Target(FUNCTION, PROPERTY_GETTER, PROPERTY_SETTER) -annotation class FailureReaction(val reactionType: String) \ No newline at end of file +annotation class FailureReaction(val failureReactionType: String) \ No newline at end of file