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

Additional APIs #30

Open
kortirso opened this issue Jul 23, 2024 · 5 comments
Open

Additional APIs #30

kortirso opened this issue Jul 23, 2024 · 5 comments

Comments

@kortirso
Copy link
Contributor

While we were integrating props into our application, we added some additional APIs that were spied on by the Jbuilder.

  1. json.optional! - defines attribute or structure and marks it as optional, during serialization this method checks condition and renders or does not render such attribute

example of usage

json.optional! :properties do
  json.optional! :value, -> { object.value } # lambda here is to avoid value calculations before checking conditions for rendering
end
  1. json.extract! - extracts the mentioned attributes or hash elements from the passed object and turns them into attributes of the JSON

example of usage - json.extract! object, :id, :unit

instead of

json.id object.id
json.unit object.unit
  1. json.partial! - renders partial without setting result to some key

@jho406 do you have any plans to integrate such features to PropsTemplate? Or maybe I can share their implementation and then dicsuss/modify/accept/reject them, what do you think?

@jho406
Copy link
Contributor

jho406 commented Jul 23, 2024

maybe I can share their implementation and then dicsuss/modify/accept/reject them, what do you think?

Yes. I'd like to discuss that!

Would you be open to creating 3 separate PRs / issues? At the very least, I can give architectural context/guidance for each of them.

@jho406
Copy link
Contributor

jho406 commented Jul 30, 2024

Nice pr in #31 @kortirso! I'll take a look later this week. I feel like that one might take a bit more time for me to review. If you are open to PRing for json.extract that seems like a great low hanging fruit and much easier for me to review. Followed by json.partial!

Also as you're migrating from jbuilder to props_template, one thing i recommend is to avoid autocamelizing your keys as it may slow your views down.

@kortirso
Copy link
Contributor Author

kortirso commented Jul 30, 2024

@jho406 what is better approach for formatting keys?

  • json.first_value with changing method format_key
  • or direct json.firstValue (if we need camelCased format)

@jho406
Copy link
Contributor

jho406 commented Jul 30, 2024

The latter.

direct json.firstValue (if we need camelCased format)

Do it directly. Its a low effort approach, speedy, and if you plan to use it in JS land, easier to search for.

@jho406
Copy link
Contributor

jho406 commented Oct 14, 2024

@kortirso Thanks for the PRs! Sorry it took a while. How the integration with props_template going?

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

No branches or pull requests

2 participants