Skip to content

Commit af8fb91

Browse files
committed
Squeeze out a few more unncessary iterations
1 parent c5653d2 commit af8fb91

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

lib/inertia_rails/renderer.rb

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,9 @@ def page
101101
}
102102
end
103103

104-
def deep_transform_props(props, parent_path = '', &block)
104+
def deep_transform_props(props, parent_path = [], &block)
105105
props.reduce({}) do |transformed_props, (key, prop)|
106-
current_path = [parent_path, key].reject(&:empty?).join('.')
106+
current_path = parent_path + [key]
107107

108108
if prop.is_a?(Hash)
109109
nested = deep_transform_props(prop, current_path, &block)
@@ -118,11 +118,11 @@ def deep_transform_props(props, parent_path = '', &block)
118118
end
119119

120120
def partial_keys
121-
(@request.headers['X-Inertia-Partial-Data'] || '').split(',').compact.map(&:to_sym)
121+
(@request.headers['X-Inertia-Partial-Data'] || '').split(',').compact
122122
end
123123

124124
def partial_except_keys
125-
(@request.headers['X-Inertia-Partial-Except'] || '').split(',').filter_map(&:to_sym)
125+
(@request.headers['X-Inertia-Partial-Except'] || '').split(',').compact
126126
end
127127

128128
def rendering_partial_component?
@@ -150,19 +150,18 @@ def keep_prop?(prop, path)
150150
true
151151
end
152152

153-
def path_prefixes(path)
154-
parts = path.split('.')
153+
def path_prefixes(parts)
155154
(0...parts.length).map do |i|
156155
parts[0..i].join('.')
157156
end
158157
end
159158

160159
def excluded_by_only_partial_keys?(path_with_prefixes)
161-
partial_keys.present? && (path_with_prefixes & partial_keys.map(&:to_s)).empty?
160+
partial_keys.present? && (path_with_prefixes & partial_keys).empty?
162161
end
163162

164163
def excluded_by_except_partial_keys?(path_with_prefixes)
165-
partial_except_keys.present? && (path_with_prefixes & partial_except_keys.map(&:to_s)).any?
164+
partial_except_keys.present? && (path_with_prefixes & partial_except_keys).any?
166165
end
167166
end
168167
end

0 commit comments

Comments
 (0)