Improve Phoenix.Presence.get_by_key/2
documentation, return value, and typespec.
#6034
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Issue
#5759 states that issue #4514 wasn't addressed properly. Checking the docs for
Phoenix.Presence.get_by_key/2
, it does have inconsistencies between its return value and the typespec it's being referred to.Improvements and Changes
Going by the given problem and proposed solution from #4514, I have made the changes:
presence
typespec that returns a map with the:metas
.presence
found under the suppliedkey
insocket_or_topic
scope, returnnil
. Pros of having anil
return value instead of[]
is that it's easier to evaluate not being a truthy value.Phoenix.Presence.get_by_key/2
to return a map instead of a list that contains themetas
information, along with some additional info that might be returned on thePhoenix.Presence.fetch/2
callback.test/phoenix/presence_test.exs
to check withis_nil
instead of[]
if the returned value on untrackedkey
is empty.