Skip to content

include meta as top level document member#97

Merged
doomspork merged 2 commits intobeam-community:masterfrom
snewcomer:meta-top-level
Mar 5, 2018
Merged

include meta as top level document member#97
doomspork merged 2 commits intobeam-community:masterfrom
snewcomer:meta-top-level

Conversation

@snewcomer
Copy link
Contributor

@snewcomer snewcomer commented Feb 25, 2018

This PR adds the ability to pass a meta map to the render function.

The current functionality relies on the meta data to be present on the data attribute. However, for example, on index routes, data is simply a List and some attributes to filter/paginate the list may need to be passed through to the response that aren't implicitly included/apart of the data.

Lmk your thoughts!

Ref #96

@snewcomer
Copy link
Contributor Author

snewcomer commented Feb 25, 2018

Another thought is ensure a user defines a key to put on the conn struct and if present, attach to the payload as a meta property instead of adding another argument to serialize. Not sure what you think about that though.

@snewcomer snewcomer force-pushed the meta-top-level branch 2 times, most recently from d30e5b8 to 8443c10 Compare February 25, 2018 19:52
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.

I tried this branch out and works like I was expecting.

if Code.ensure_loaded?(Phoenix) do
def render("show.json", %{data: data, conn: conn, params: params, meta: meta}),
do: show(data, conn, params, meta: meta)
def render("show.json", %{data: data, conn: conn, meta: meta}),
Copy link
Contributor Author

Choose a reason for hiding this comment

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

One unrelated curiosity:

If I define a render function in my controller, how does the conn parameter get in there?

render(conn, "index.json", %{data: my_list, meta: meta})

Choose a reason for hiding this comment

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

conn is always merged into the assigns data, because the view doesn't mutate/return a conn its treated as data instead of the subject of the function.

@snewcomer
Copy link
Contributor Author

@jeregrine Looks like 18.3 is failing here and on master. Only on elixir 1.6 is otp 18 not supported. Would you like me to remove 18.3 from travis? Or is there another way to do this?

https://github.com/elixir-lang/elixir/blob/master/lib/elixir/pages/Compatibility%20and%20Deprecations.md#compatibility-between-elixir-and-erlangotp

https://travis-ci.org/jeregrine/jsonapi/jobs/347070137
https://travis-ci.org/jeregrine/jsonapi/jobs/346951834

@jeregrine
Copy link

jeregrine commented Mar 5, 2018 via email

@doomspork
Copy link
Member

@snewcomer could you squash your commits to re-trigger Travis? 😁

@snewcomer snewcomer force-pushed the meta-top-level branch 2 times, most recently from 02b64c3 to f14a89f Compare March 5, 2018 21:28
@doomspork doomspork merged commit 98d1e94 into beam-community:master Mar 5, 2018
@doomspork
Copy link
Member

@jeregrine do you want me to cut a new release?

@jeregrine
Copy link

I trust your judgement here :)

@snewcomer snewcomer mentioned this pull request Mar 23, 2018
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.

3 participants