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

Add to view custom attribute close #89 #92

Merged
merged 3 commits into from
Jan 9, 2018

Conversation

snewcomer
Copy link
Contributor

Ref #89

Copy link
Member

@doomspork doomspork left a comment

Choose a reason for hiding this comment

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

@snewcomer this is a good first go, I've left some feedback and questions. I do think we should think about whether we want to be passing conn into the functions, that opens the door for misuse and confusing behavior.

Let's think about it a bit and give @jeregrine a chance to share his thoughts 👍

end)
end

defp merge(intermediate_map, field, value) do
Copy link
Member

Choose a reason for hiding this comment

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

What does merge/3 offer us over just using Map.put/3 directly?

visible_fields(data)
visible_fields = fields() -- hidden()

Enum.reduce(visible_fields, %{}, fn field, intermediate_map ->
Copy link
Member

Choose a reason for hiding this comment

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

Why reduce/3 vs map/2?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was to ensure the return type was a Map, which is what Map.take was doing before.


Enum.reduce(visible_fields, %{}, fn field, intermediate_map ->
try do
merge(intermediate_map, field, apply(__MODULE__, field, [data, conn]))
Copy link
Member

Choose a reason for hiding this comment

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

Can we do something like this to DRY things up a bit?

value =
  try do
    apply(__MODULE__, field, [data, conn])
  rescue
    _e -> Map.get(data, field)
  end

Map.put(intermediate_map, field, value)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ah much better 💯

Copy link
Contributor Author

@snewcomer snewcomer left a comment

Choose a reason for hiding this comment

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

@doomspork Good calls. So the only reason to also pass conn would be to get at the current user or something like that. So if your API is returning a list of users, for every user you could ensure that only the current logged in user's email was sent back. Lmk your thoughts!

visible_fields(data)
visible_fields = fields() -- hidden()

Enum.reduce(visible_fields, %{}, fn field, intermediate_map ->
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was to ensure the return type was a Map, which is what Map.take was doing before.


Enum.reduce(visible_fields, %{}, fn field, intermediate_map ->
try do
merge(intermediate_map, field, apply(__MODULE__, field, [data, conn]))
Copy link
Contributor Author

Choose a reason for hiding this comment

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

ah much better 💯

@doomspork doomspork merged commit 327bf64 into beam-community:master Jan 9, 2018
@doomspork
Copy link
Member

Thank you @snewcomer! I want to review #87 and then we can cut a new release 😁

@snewcomer snewcomer deleted the custom-attribute branch January 9, 2018 23:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants