Skip to content

Added null return if there are no subscriptions. #101

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

volkovasystems
Copy link

Currently, publish method returns true or false, in the documentation, it says

"amplify.publish returns a boolean indicating whether any subscriptions returned false. The return value is true if none of the subscriptions returned false, and false otherwise. Note that only one subscription can return false because doing so will prevent additional subscriptions from being invoked."

Quoting: "The return value is true if none of the subscriptions returned false, and false otherwise."

What if there are no subscriptions yet? It will still return true?

So this is a suggestion to the feature to inform that when there are not subscriptions yet it will return null.

Currently, publish method returns true or false, in the documentation, it says 

"amplify.publish returns a boolean indicating whether any subscriptions returned false. The return value is true if none of the subscriptions returned false, and false otherwise. Note that only one subscription can return false because doing so will prevent additional subscriptions from being invoked."

Quoting: "The return value is true if none of the subscriptions returned false, and false otherwise."

What if there are no subscriptions yet? It will still return true? 

So this is a suggestion to the feature to inform that when there are not subscriptions yet it will return null.
@dcneiner
Copy link
Contributor

@volkovasystems Thanks for putting this together! This would be a breaking change in that I don't suspect most users would attempt to evaluate the return value with strict equality to false.

var pub = amplify.publish( ".." );
if (!pub) {
  // respond to cancel
}

Since null is falsey in JavaScript, it would cause existing code to act as if the subscription were cancelled via return false.

Can you comment with some more detail of the situation when you need to know at publish time when there are no subscribers to a particular topic?

@volkovasystems
Copy link
Author

@dcneiner Thanks for the reply, and I didn't see that coming. That would cause world destruction if some developers did that.

I was just thinking that how should we know if there are subscriptions or not. Something that will let us know if there's already a subscription for that event. There's no really particular scenario but it would be helpful if we can determine that.

If this is not possible then we can just expose a function or a property to test if there are already subscriptions for that particular event.

Something like this, amplify.hasSubscriptions( "event name" );

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.

2 participants