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

Remove 'callback' param from the unsubscribe function. #18

Open
nashvail opened this issue May 20, 2018 · 0 comments
Open

Remove 'callback' param from the unsubscribe function. #18

nashvail opened this issue May 20, 2018 · 0 comments

Comments

@nashvail
Copy link

Inside the unsubscribe function, the code is

var subs = cache[callback ? handle : handle[0]], 
  callback = callback || handle[1],
  len = subs ? subs.length : 0;

In case a callback is passed,

  • subs becomes undefined because an array is being passed to the cache object.
  • callback local variable holds the passed in callback
  • len becomes 0.

The final check then...

if (subs[len] === callback) { // undefined[0] => always false
  subs.splice(len, 1);
}

...doesn't result in anything getting spliced from subs.

Please help me see the reason behind having callback as param if I have minsunderstood the code.

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