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

Improve Phoenix.Presence.get_by_key/2 documentation, return value, and typespec. #6034

Closed
wants to merge 3 commits into from

Conversation

jaspervanbrian
Copy link

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:

  • Improve and fix the presence typespec that returns a map with the :metas.
  • If no presence found under the supplied key in socket_or_topic scope, return nil. Pros of having a nil return value instead of [] is that it's easier to evaluate not being a truthy value.
  • Change the documented return value of Phoenix.Presence.get_by_key/2 to return a map instead of a list that contains the metas information, along with some additional info that might be returned on the Phoenix.Presence.fetch/2 callback.
  • Change test specs on test/phoenix/presence_test.exs to check with is_nil instead of [] if the returned value on untracked key is empty.

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.

1 participant