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

Adding Phoenix.Presence functionality #87

Open
wants to merge 11 commits into
base: main
Choose a base branch
from

Conversation

alanj853
Copy link

@alanj853 alanj853 commented Jun 22, 2021

Should address #39

alanj853 added 8 commits June 22, 2021 14:36
First pass at adding Phoenix.Presence
This allows us to wait for our current handler to execute fully and the client to prepare itself before it receives any data
socket.assigns
|> Map.get(:absinthe, %{})
|> Map.get(:opts, [])
|> Keyword.get(:context, %{handler: nil})

Choose a reason for hiding this comment

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

why do we need %{handler: nil} here?

Copy link

Choose a reason for hiding this comment

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

Because you cannot do Map.get(nil, :handler) which will happen if the context is missing from opts

Copy link
Contributor

Choose a reason for hiding this comment

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

This whole chain feels like it would be improved with use of Access since it is nil resilient:

socket.assigns[:absinthe][:opts][:context][:handler]

@doc """
Function to call the Phoenix.Presence.list/1 callback from the module that the user has configured in __absinthe_presence_config__.
"""
def list(socket = %{assigns: %{__absinthe_presence_config__: presence_config}})

Choose a reason for hiding this comment

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

Elixir can pattern match at multiple levels

Suggested change
def list(socket = %{assigns: %{__absinthe_presence_config__: presence_config}})
def list(socket = %{assigns: %{__absinthe_presence_config__: %{module: module}}}) when is_binary(module) do
module.list(socket)
end

Copy link
Contributor

Choose a reason for hiding this comment

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

is_binary module is wrong through, would need to be is_atom.

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.

4 participants