Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@mikehedman
Copy link

If options are not passed to the access-token.findForRequest() function, then the callback argument will be undefined. This makes the options truly optional as the docs prescribe.

If options are not passed to the access-token.findForRequest() function, then the callback argument will be undefined.  This makes the options truly optional as the docs prescribe.
@slnode
Copy link

slnode commented Nov 7, 2014

Can one of the admins verify this patch? To accept patch and trigger a build add comment ".ok\W+to\W+test."

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IIRC calling Array.prototype.slice on arguments incurs performance penalty.

This is the usual way of handling optional args:

if (cb === undefined && typeof options === 'function') {
  cb = options;
  options = {};
}

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bajtos I agree that the structure you suggest is very common, and in fact is the way that I initially implemented it! But then I thought it would be good to search through the existing LoobBack code, and this is the structure that is used throughout the existing codebase - so this is what I submitted.
But this is a case of following convention - that is, I agree that the way you suggest would be faster, and is easier to read. Any idea of the benefit of the "loopback way"?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any idea of the benefit of the "loopback way"?

I am not sure as I don't use it. I suppose it supports arbitrary number of optional arguments before the last callback arg. I.e. the following call will work correctly too:

AccessToken.findForRequest(req, options, 1, 2, 3, callbackFn);

@bajtos
Copy link
Member

bajtos commented Nov 10, 2014

@slnode ok to test

@bajtos
Copy link
Member

bajtos commented Nov 10, 2014

@mikehedman thank you for the pull request, please address my comment above. Can you also add a unit-test to verify the implementation and prevent regressions in the future?

@mikehedman
Copy link
Author

And yes, I'll work up some testing as well.

@bajtos
Copy link
Member

bajtos commented Nov 11, 2014

I noticed the patch is reverting some of the changes made on the master branch. If you want to bring your feature branch up-to-date with the upstream master, use git rebase master && git push -f.

In this case, I'd suggest you to remove the two merge commits first, before starting any new work:

$ git stash
$ git reset --hard 580a3a1
$ git rebase master 
$ git push -f
$ git stash pop

@mikehedman
Copy link
Author

Folks, I spent quite some time looking at the existing unit tests, and the function I changed (and its dependencies), and I'm just not currently qualified to write an effective test for this change. I just don't know enough about how LoopBack's internals work. I'll get there someday, but I'm not there now. So either we can go forward with this PR as it stands now, someone else can add the testing, or we can table the PR, and I'll try to return to it when I'm better equipped to write the tests. Sorry about that, Mike.

@mikehedman
Copy link
Author

@bajtos - I've reverted the merges as you suggested. I'll work on being more attentive to the git parts. Thanks for your help.

@bajtos
Copy link
Member

bajtos commented Nov 12, 2014

@mikehedman I'll take a look and either advise you how to write the unit test or submit the patch myself.

@bajtos bajtos self-assigned this Nov 13, 2014
@bajtos
Copy link
Member

bajtos commented Nov 14, 2014

Closing in favour of #813

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

Successfully merging this pull request may close these issues.

4 participants