Improve Phoenix.Presence.get_by_key/2 documentation, return value, and typespec.#6042
Open
jaspervanbrian wants to merge 1 commit intophoenixframework:mainfrom
Open
Conversation
- Change presence typespec, and use presence type for presences typespec. - Return `nil` for empty presence on `Presence.get_by_key/2`. - Assert is_nil instead of empty array on `Presence.get_by_key/2` test. - Improve documentation of `Presence.get_by_key/2` callback.
Phoenix.Presence.get_by_key/2 documentation, return value, and typespec.
Contributor
|
Just ran into this; it feels bit odd to get back either a map or an empty list, 'nil` feels like a good solution. |
Contributor
|
Changing the return value is a breaking change, so I'm not sure we can do this (cc @josevalim). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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:
presencetypespec that returns a map with the:metas.presencefound under the suppliedkeyinsocket_or_topicscope, returnnil. Pros of having anilreturn value instead of[]is that it's easier to evaluate not being a truthy value.Phoenix.Presence.get_by_key/2to return a map instead of a list that contains themetasinformation, along with some additional info that might be returned on thePhoenix.Presence.fetch/2callback.test/phoenix/presence_test.exsto check withis_nilinstead of[]if the returned value on untrackedkeyis empty.