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

Why does Events.off need to return the index? #199

Closed
zepumph opened this issue Dec 21, 2018 · 6 comments
Closed

Why does Events.off need to return the index? #199

zepumph opened this issue Dec 21, 2018 · 6 comments

Comments

@zepumph
Copy link
Member

zepumph commented Dec 21, 2018

@samreid And I couldn't find any usages of the return value from off or offStatic. I think it would be good to double check with @jonathanolson before getting rid of it though.

@zepumph
Copy link
Member Author

zepumph commented Dec 21, 2018

I used (return|=){1} (\w*\.){0,3}off(Static){0,1}\( to search for usages.

@samreid samreid self-assigned this Dec 21, 2018
@samreid
Copy link
Member

samreid commented Feb 5, 2019

There is some usage here:

https://github.com/phetsims/scenery/blob/0eaff198894fa9470c47d86dca082aa97f0b70c9/js/nodes/Node.js#L5121-L5130

    offStatic: function offStaticOverride( eventName, listener ) {
      var index = Events.prototype.offStatic.call( this, eventName, listener );

      // Throw an error when removing a non-listener (except when the Node has already been disposed)
      if ( assert && !this.isDisposed ) {
        assert && assert( index >= 0, 'Node.offStatic was called but no listener was removed' );
      }
      this.onEventListenerRemoved( eventName, listener );
      return index;
    },

@samreid
Copy link
Member

samreid commented Feb 5, 2019

But in that case it would be equally good to return true or false, or maybe to have Events do its own assertion. @jonathanolson what do you think?

@samreid samreid removed their assignment Feb 5, 2019
@jonathanolson
Copy link
Contributor

I'm fine with that feature being removed/changed, I don't remember using it. For Scenery, having strict error checking (fail on trying to remove a non-listener) would be nice.

@samreid
Copy link
Member

samreid commented Apr 3, 2019

Proposed fix is here. I had to put a band-aid on one call site to prevent erroring. When I moved the error checking directly to Events.js, fuzz testing revealed a problem in many (but not all sims) that involved removing listeners from TransformTracker.js. For now, I adopted the prior behavior of not checking those listeners. But based on #199 (comment) I'm wondering if this is a latent bug, or if it should remain unchecked. @jonathanolson can you take a look?

@samreid samreid assigned jonathanolson and unassigned samreid Apr 3, 2019
@zepumph zepumph removed their assignment Apr 4, 2019
@samreid
Copy link
Member

samreid commented Jan 30, 2021

Events was deleted in phetsims/scenery#490, closing.

@samreid samreid closed this as completed Jan 30, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants