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

README: Example on getting the tokens you should remove #323

Merged
merged 4 commits into from
Jun 1, 2018
Merged

README: Example on getting the tokens you should remove #323

merged 4 commits into from
Jun 1, 2018

Conversation

johanforssell
Copy link
Contributor

Example of how to find the tokens which you couldn't send to.
I'm maching the two arrays together and then filtering it to get a list of tokens.

Include example of how to find the tokens which you couldn't send to.

I'm maching the two arrays together and then filtering it to get a list of tokens.
README.md Outdated
sender.send(message, { registrationTokens: registrationTokens }, function (err, response) {
var failed_tokens = response.results
.map((res, i) => !!res.error ? registrationTokens[i] : undefined)
.filter(token => !!token);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Thank you for the time you took to contribute 😄

Here are my thoughts:

Isn't the code wrong, mapping all responses without errors (where res.error is falsy, so !!res.error == false) to undefined? Shouldn't it be the opposite?

I would prefer using null to undefined in the code example, too.

In addition, I think the !! are adding confusion, as the evaluation would be the same without them...

Other than that, it is a good example 😄

@hypesystem
Copy link
Collaborator

Thanks for the quick update 😄

I still think the check for res.error might be wrong --- shouldn't it be !res.error?

@johanforssell
Copy link
Contributor Author

johanforssell commented May 31, 2018

My thinking is that the .map() goes through the array of results. Where there is an error, pick the token from the other array. Otherwise, pick nothing/null. Remember, we're collecting the tokens of erronous sends, in order to purge them from the database.

@hypesystem
Copy link
Collaborator

Ah yes, you are absolutely right, I was just reading it wrong! I blame being tired 😄

Maybe we could avoid people like me misunderstanding the code in the future by adding a bit more of a comment?

@hypesystem
Copy link
Collaborator

This looks good to me! Remember to add yourself to contributors in package.json 😄

@eladnava any comments on this before we merge?

@eladnava
Copy link
Collaborator

eladnava commented Jun 1, 2018

Just reviewed, looks good to me! 💯 Thanks so much @johanforssell for the excellent work.

@hypesystem
Copy link
Collaborator

Thanks for the contribution @johanforssell ! 😄

@hypesystem hypesystem merged commit a63a4b4 into ToothlessGear:master Jun 1, 2018
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.

3 participants