Rob Gordon Posted April 12, 2020 Share Posted April 12, 2020 Question about the InteractionManager: The following works as expected: InteractionManager.on("pointerdown", handlePointerDown); function handlePointerDown(e) { InteractionManager.off("pointerdown", handlePointerDown); console.log("hello", e.data.identifier); } console: "hello" 1 The following adds the event twice (I would have not expected that to happen with the same event/function): InteractionManager.on("pointerdown", handlePointerDown); InteractionManager.on("pointerdown", handlePointerDown); function handlePointerDown(e) { InteractionManager.off("pointerdown", handlePointerDown); console.log("hello"); } console: "hello" 1 (2) Even with the issue above, I would have expected 'removeAllListeners' to eliminate the second call, but it does not: InteractionManager.on("pointerdown", handlePointerDown); InteractionManager.on("pointerdown", handlePointerDown); function handlePointerDown(e) { InteractionManager.removeAllListeners(); console.log("hello"); } console: "hello" 1 (2) Is this the way this stuff is supposed to work? I could certainly manage all events very explicitly...but it would be so much simpler to be able to 'removeAllListeners' when needed instead of using 'off' for every single event. Cheers, r o b Quote Link to comment Share on other sites More sharing options...
ivan.popelyshev Posted April 12, 2020 Share Posted April 12, 2020 Hi! You are trying to remove those events inside "handle". According to EventEmitter3 source (which i took in node_modules but you can look in their github), removeAllListeners creates new "events" object in "removeAllListeners", so its really cant affect already running FOR in the same stack - that FOR goes through old list. According to sources, InteractionManager just uses "emit" method from the same library and doesn't care about corner cases like yours. I suggest to store something in "e" and chek if flag is true, there's already "e.stopped" field which becomes "true" if you call "e.stopPropagation()". If you dont like default behaviour, you can create an issue in pixijs github, and ask to clarify this case because its really really needed in your project and explain that two extra lines "emitCarefully" method will really help other users. Or just make PR to change the docs to clarify that somewhere... Quote Link to comment Share on other sites More sharing options...
Rob Gordon Posted April 13, 2020 Author Share Posted April 13, 2020 Thanks Ivan. I had looked through the EventEmitter3 source and I believe I understand why it works this way. I can absolutely work with/around it - so I wouldn't say this is really needed at the moment. It's probably good practice to keep track of event states anyways... I would have liked 'removeAllListeners' as a convenience feature to really clean out all events from the target (InteractionManager in my case). Would make my code a whole lot cleaner. On my current project i have many interactive elements...so I try to keep their events 'off' until they are activated/required. I have found that too many listeners at once can really slow things down. Cheers! Quote Link to comment Share on other sites More sharing options...
ivan.popelyshev Posted April 13, 2020 Share Posted April 13, 2020 (edited) > I would have liked 'removeAllListeners' as a convenience feature to really clean out all events from the target well it does clear all, just not affecting current FOR's in stack concurrent updates Edited April 13, 2020 by ivan.popelyshev Quote Link to comment Share on other sites More sharing options...
Rob Gordon Posted April 14, 2020 Author Share Posted April 14, 2020 Understood! ivan.popelyshev 1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.