Skip to content
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

removeListener does not remove listener #3

Open
jokigenki opened this issue Apr 8, 2024 · 1 comment
Open

removeListener does not remove listener #3

jokigenki opened this issue Apr 8, 2024 · 1 comment

Comments

@jokigenki
Copy link

Removing a listener does not work at all.

Log.d(TAG, "---------------Test 1------------")
val sig = Signals.localSignal(TestSignal1::class)
Log.d(TAG, "BEFORE has: ${sig.hasListeners()}") // false
sig.addListener(::testSig)
Log.d(TAG, "AFTER ADD has: ${sig.hasListeners()}") // true
sig.removeListener(::testSig)
Log.d(TAG, "AFTER REMOVE has: ${sig.hasListeners()}") // true

Log.d(TAG, "---------------Test 2------------")
val sig2 = Signals.localSignal(TestSignal2::class)
Log.d(TAG, "BEFORE has: ${sig2.hasListeners()}") // false
sig2.addListener { s -> Log.d("test", s) }
Log.d(TAG, "AFTER ADD has: ${sig2.hasListeners()}") // true
sig2.removeListener { s -> Log.d("test", s) }
Log.d(TAG, "AFTER REMOVE has: ${sig2.hasListeners()}") // true

Log.d(TAG, "---------------Test 3------------")
val sig3 = Signals.signal(TestSignal3::class)
Log.d(TAG, "BEFORE has: ${sig3.hasListeners()}") // false
sig3.addListener(::testSig)
Log.d(TAG, "AFTER ADD has: ${sig3.hasListeners()}") // true
sig3.removeListener(::testSig)
Log.d(TAG, "AFTER REMOVE has: ${sig3.hasListeners()}") // true

Log.d(TAG, "---------------Test 4------------")
val sig4 = Signals.signal(TestSignal4::class)
Log.d(TAG, "BEFORE has: ${sig4.hasListeners()}") // false
sig4.addListener { s -> Log.d("test", s) }
Log.d(TAG, "AFTER ADD has: ${sig4.hasListeners()}") // true
sig4.removeListener { s -> Log.d("test", s) }
Log.d(TAG, "AFTER REMOVE has: ${sig4.hasListeners()}") // true

fun testSig(s: String) {
}

fun interface TestSignal1 {
    fun test(s: String)
}

fun interface TestSignal2 {
    fun test(s: String)
}

fun interface TestSignal3 {
    fun test(s: String)
}

fun interface TestSignal4 {
    fun test(s: String)
}

 ---------------Test 1------------
BEFORE has: false
AFTER ADD has: true
AFTER REMOVE has: true
---------------Test 2------------
BEFORE has: false
AFTER ADD has: true
AFTER REMOVE has: true
---------------Test 3------------
 BEFORE has: false
AFTER ADD has: true
AFTER REMOVE has: true
---------------Test 4------------
BEFORE has: false
AFTER ADD has: true
AFTER REMOVE has: true
@jokigenki jokigenki changed the title Remove listener does not remove listener removeListener does not remove listener Apr 8, 2024
@jokigenki
Copy link
Author

Some further info. In ListenersList.add, map.containsKey(listener) does not match the listener in this case (it always returns false), but map.any{ it == listener} returns true

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant