Skip to content

Add smart merging with match_on option #234

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

skryukov
Copy link
Contributor

@skryukov skryukov commented Jun 17, 2025

@skryukov skryukov changed the title Add merge strategies support Add match_on support Jun 20, 2025
@skryukov skryukov changed the title Add match_on support Add smart merging with match_on option Jun 20, 2025
@BrandonShar BrandonShar requested a review from Copilot June 20, 2025 22:07
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR introduces a match_on option to enable smart merging on specific object keys when using merge, deep_merge, and deferred merge props. It updates the API surfaces, rendering logic, tests, and documentation to support generating a new matchPropsOn field in the Inertia response.

  • Extend merge, deep_merge, and defer helpers to accept a match_on parameter.
  • Enhance the renderer to collect and output matchPropsOn based on provided keys.
  • Update specs, dummy controller, and docs to demonstrate and validate smart merging behavior.

Reviewed Changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
spec/inertia/rendering_spec.rb Tests updated to expect match_on props and new matchPropsOn.
spec/dummy/app/controllers/inertia_render_test_controller.rb Added examples of merge(match_on:) and defer(..., match_on:).
lib/inertia_rails/renderer.rb Built all_merge_props, collected matchPropsOn, and adjusted existing merge logic.
lib/inertia_rails/merge_prop.rb Added match_on attribute to MergeProp.
lib/inertia_rails/defer_prop.rb Added match_on attribute to DeferProp.
lib/inertia_rails/inertia_rails.rb Updated helper methods (merge, deep_merge, defer) to pass match_on.
lib/inertia_rails/generators/helper.rb Renamed guess_typescript to uses_typescript?.
lib/inertia_rails/generators/controller_template_base.rb Updated default for :typescript option to call uses_typescript?.
docs/guide/merging-props.md Added documentation and examples for match_on.
docs/guide/deferred-props.md Linked merging-props guide under “Combining with mergeable props.”

Comment on lines +113 to +115
match_props_on = all_merge_props.filter_map do |key, prop|
prop.match_on.map { |ms| "#{key}.#{ms}" } if prop.match_on.present?
end.flatten
Copy link
Preview

Copilot AI Jun 20, 2025

Choose a reason for hiding this comment

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

[nitpick] You can simplify this logic by using flat_map instead of filter_map plus flatten, for example:

match_props_on = all_merge_props.flat_map do |key, prop|
  prop.match_on.present? ? prop.match_on.map { |ms| "#{key}.#{ms}" } : []
end
Suggested change
match_props_on = all_merge_props.filter_map do |key, prop|
prop.match_on.map { |ms| "#{key}.#{ms}" } if prop.match_on.present?
end.flatten
match_props_on = all_merge_props.flat_map do |key, prop|
prop.match_on.present? ? prop.match_on.map { |ms| "#{key}.#{ms}" } : []
end

Copilot uses AI. Check for mistakes.

@skryukov skryukov marked this pull request as ready for review June 21, 2025 19:10
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.

1 participant