Jump to content

InteractionManager


Rob Gordon
 Share

Recommended Posts

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

Link to comment
Share on other sites

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...

Link to comment
Share on other sites

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!

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...