Skip to content
This repository has been archived by the owner on Dec 12, 2018. It is now read-only.

Documented method signature for next in collectionResource.detect and implementation do not match. #589

Open
kirps opened this issue Jan 5, 2017 · 4 comments

Comments

@kirps
Copy link

kirps commented Jan 5, 2017

The docs indicate that the iterator in collectionResource.detect must call it's next argument with the signature next(err, test) .

https://docs.stormpath.com/nodejs/jsdoc/CollectionResource.html#detect__anchor

However, printing out the next function reveals that it only accepts one argument, see below

function (v) {
    if (cb && check(v)) {
        cb(getResult(true, x));
        cb = iterator = false;
    }
    callback();
}

Practically, it appears that the signature should be next(test) to get the described behavior.

For instance I was calling next(null, test) as I had no errors and that resulted in all resources being visited and null being passed as the foundResource argument of doneCallback

@kirps
Copy link
Author

kirps commented Jan 5, 2017

The doneCallback signature is also incorrectly documented.

it is currently doneCallback(foundResource)

rather than the documented doneCallback(err, foundResource)

@mdeggies
Copy link
Member

mdeggies commented Jan 5, 2017

Thanks @kirps, I'm taking a look.

@mdeggies
Copy link
Member

mdeggies commented Jan 5, 2017

Yep, you're right. The correct snippet is this:

client.getApplication(applicationHref, function(err, application) {
	if (!err) {

		function iterator(account, next) {
			next(account.customData.favoriteFood === 'pizza');
		}

		function doneCallback(foundAccount) {
			console.log('Guess who likes pizza??');
			console.log(foundAccount.email);
		}

		application.getAccounts({ expand: 'customData' }, function (err, collection) {
			if (!err) {
				collection.detect(iterator, doneCallback);
			}
		});
	}
});

Thanks for pointing this out! I'll update the docs.

@mdeggies
Copy link
Member

mdeggies commented Jan 6, 2017

Updates for collection resource here: #591

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants