dush icon indicating copy to clipboard operation
dush copied to clipboard

.off behaves incorrectly

Open sqal opened this issue 7 years ago • 10 comments

Test case:

const emitter = dush()

const handler1 = () => { console.log('a') }
const handler2 = () => { console.log('a') }

emitter.on('a', handler1)
emitter.on('a', handler2)
emitter.off('a', handler1)

What is expected?

handler2 should not be removed

What is actually happening?

handler2 is removed because the lib uses fn.toString() to identify a function and source code of both functions looks the same

sqal avatar Oct 05 '17 08:10 sqal

Hi ! I stumbled on this issue as well, @tunnckoCore would you be interested in a PR for this one ?

superguigui avatar Nov 14 '18 15:11 superguigui

That's "known bug", based on how I decided (which is pretty weird and tricky hack) to do the off-ing. It is string based. And if both functions are the same well then yea.

I definitely don't remember why I chose that hack, instead of doing it with few other possible ways.

tunnckoCore avatar Nov 14 '18 16:11 tunnckoCore

I made some tests and if you remove the string based comparaison and replace it with reference based comparaison, it seems to be ok.

I'm guessing you went with string based because the "off" function was not able to find the wrapped version of the handler. My solution stores a reference to the original handler in the wrapper rather than a string. It's actually very little change and every test is still passing (even losing a couple bytes in the final bundle).

Any other reason you used string based comparaison that i'm not thinking of ?

I have a PR almost ready !

superguigui avatar Nov 14 '18 16:11 superguigui

My solution stores a reference to the original handler in the wrapper rather than a string.

I was using this before ;d

But anyway I'm not hard about that, so PR is welcome.

(Oh, I should definitely update the repo boilerplate and stuff (oh god, there's no automatic publish and release here?! so it's really old of haha) ;d But if you are okey with that, great!)

tunnckoCore avatar Nov 14 '18 16:11 tunnckoCore

Hi, sorry to bother. I ran into the same problem. Is there any news about a fix release?

dwightjack avatar Dec 04 '18 09:12 dwightjack

There's #42 but conflicts should be resolved so I can merge.

tunnckoCore avatar Dec 04 '18 13:12 tunnckoCore

Any news on this @tunnckoCore ?

kouts avatar Apr 25 '20 09:04 kouts

@kouts, sorry, not for now. I can come back in few days and look into an update. I'm switching and upgrading machines now.

tunnckoCore avatar Apr 26 '20 03:04 tunnckoCore

@kouts, sorry, not for now. I can come back in few days and look into an update. I'm switching and upgrading machines now.

Hi, just wanna check if there is a update going on. thanks in advanced!

boli-duality avatar May 09 '24 10:05 boli-duality

@boli-duality I did not expect to receive notifications from this repo ^^. The project is most likely dead, not updated for 7 years. I would advise you to simply find another event emitter. mitt is fine.

sqal avatar May 09 '24 10:05 sqal