-
Notifications
You must be signed in to change notification settings - Fork 20.5k
#13150 - Get number of functions in $.Callback() #1111
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
Conversation
|
Having some unit test would probably have shown the issue ;) |
|
Ah thanks! Will do unit tests in the future. Patched it and had a go at it with QUnit this time. |
|
@adamcoulombe, you still need to add a unit test showing the usage of the function if you want it to have a shot of being added to the library. |
|
I'm not inclined to land this without a use case. @jaubourg what do you think? I am concerned that the caller would need/want to know more about the state of the list and that leads us down a road we don't want to follow. |
|
I have nothing against the patch per se. I hear your concern but we already have |
|
The main use case is just knowing whether a $.Callbacks object has had functions added to it. Like @jaubourg pointed out, you can use Knowing the list length seems like the simplest and most flexible way of doing this. The other way I was thinking, if you're not into the idea of adding |
|
I kinda like the idea of using |
removed .size() and instead modified the .has() method to alternatively accept no arguments to check if there are any callbacks attached or not updated unit tests with .has() method
|
Adding a new use-case for |
src/callbacks.js
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just use if (fn) and swap if/else case
Also updated comments with descriptions that reflect updated .has() method
|
thanks @staabm I've updated the logic to use |
|
I like the idea of using |
src/callbacks.js
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you want a boolean but still more compact an expression, you could go for:
return !!( list && list.length && ( !fn || jQuery.inArray(fn,list) > -1 ) );
Unless other think it too cryptic (and provided I got the logic right, which is not a given :P)
|
Yes. There is value in this and having |
|
@jaubourg thanks for the help! The |
|
Is this ready? |
|
Unit test needs some reformatting but it's good for a merge and we can make those (very minor) adjustements after. |
|
@dmethvin Done. |
Adds a .size() function to the $.Callback() object to return the list length so we can know if/how many functions have been added