-
Notifications
You must be signed in to change notification settings - Fork 83
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
base: main
Are you sure you want to change the base?
Conversation
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
Add ready_for_data clause
socket.assigns | ||
|> Map.get(:absinthe, %{}) | ||
|> Map.get(:opts, []) | ||
|> Keyword.get(:context, %{handler: nil}) |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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}}) |
There was a problem hiding this comment.
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
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 | |
There was a problem hiding this comment.
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
.
Should address #39