Skip to content

Commit

Permalink
deep merge without AS
Browse files Browse the repository at this point in the history
  • Loading branch information
mensfeld committed Sep 3, 2024
1 parent 22bd047 commit 9add175
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Karafka Web Changelog

## 0.10.2 (Unreleased)
- [Fix] Undefined method `deep_merge` for an instance of Hash.
- [Fix] Prevent live-polling on elements wrapped in a button.
- [Fix] Fix errors extractor failure on first message-less tick / eofed

Expand Down
25 changes: 24 additions & 1 deletion lib/karafka/web/ui/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ class Base < Roda
# @param query_data [Hash] query params we want to add to the current path
path :current do |query_data = {}|
# Merge existing request parameters with new query data
merged_params = request.params.deep_merge(query_data)
merged_params = deep_merge(request.params, query_data)

# Flatten the merged parameters
flattened_params = flatten_params('', merged_params)
Expand Down Expand Up @@ -162,6 +162,29 @@ def render_response(response)
def params
Controllers::Requests::Params.new(request.params)
end

private

# Merges two hashes deeply, combining nested hashes recursively.
#
# @param hash1 [Hash] The first hash to merge.
# @param hash2 [Hash] The second hash to merge.
# @return [Hash] A new hash that is the result of a deep merge of the two provided hashes.
def deep_merge(hash1, hash2)
merged_hash = hash1.dup

hash2.each_pair do |k, v|
tv = merged_hash[k]

merged_hash[k] = if tv.is_a?(Hash) && v.is_a?(Hash)
deep_merge(tv, v)
else
v
end
end

merged_hash
end
end
end
end
Expand Down

0 comments on commit 9add175

Please sign in to comment.