-
Notifications
You must be signed in to change notification settings - Fork 75
Support dot notation for :only keys in partial reloads #163
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
Changes from 2 commits
a42ea77
c5653d2
af8fb91
776da3a
a62b21a
c6df93d
0c566ee
c4606ef
2027984
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -74,25 +74,21 @@ def merge_props(shared_data, props) | |||||
end | ||||||
|
||||||
def computed_props | ||||||
_props = merge_props(shared_data, props).select do |key, prop| | ||||||
if rendering_partial_component? | ||||||
partial_keys.none? || key.in?(partial_keys) || prop.is_a?(AlwaysProp) | ||||||
else | ||||||
!prop.is_a?(LazyProp) | ||||||
end | ||||||
end | ||||||
_props = merge_props(shared_data, props) | ||||||
|
||||||
drop_partial_except_keys(_props) if rendering_partial_component? | ||||||
deep_transform_props _props do |prop, path| | ||||||
next [:dont_keep] unless keep_prop?(prop, path) | ||||||
|
||||||
|
||||||
deep_transform_values _props do |prop| | ||||||
case prop | ||||||
transformed_prop = case prop | ||||||
when BaseProp | ||||||
prop.call(controller) | ||||||
when Proc | ||||||
controller.instance_exec(&prop) | ||||||
else | ||||||
prop | ||||||
end | ||||||
|
||||||
[:keep, transformed_prop] | ||||||
end | ||||||
end | ||||||
|
||||||
|
@@ -105,19 +101,19 @@ def page | |||||
} | ||||||
end | ||||||
|
||||||
def deep_transform_values(hash, &block) | ||||||
return block.call(hash) unless hash.is_a? Hash | ||||||
|
||||||
hash.transform_values {|value| deep_transform_values(value, &block)} | ||||||
end | ||||||
def deep_transform_props(props, parent_path = '', &block) | ||||||
|
||||||
props.reduce({}) do |transformed_props, (key, prop)| | ||||||
current_path = [parent_path, key].reject(&:empty?).join('.') | ||||||
|
current_path = [parent_path, key].reject(&:empty?).join('.') | |
current_path = path + [key] |
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I noticed that 'what_about_empty_hash' => {},
example will fail, here's a fix:
if prop.is_a?(Hash) | |
if prop.is_a?(Hash) && prop.any? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
all the prop filtering logic now lives in one concise place. i debated pulling this out into a class, but I don't think the cleanliness is worth the extra indirection.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe worth nothing that if we're in a partial reload, we'll end up calculating this array for every single prop key. That should still be way faster than fully evaluating all of those props, though.
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can replace .filter_map(&:to_sym)
in the partial_except_keys
and then stop calling .map(&:to_s)
here
And same for partial_keys
partial_except_keys.present? && (path_with_prefixes & partial_except_keys.map(&:to_s)).any? | |
partial_except_keys.present? && (path_with_prefixes & partial_except_keys).any? |
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why return this array from the block now? Well, the block has two jobs 1) to filter out props we don't need and 2) transform the keepers into their final format. We want track those separately so that the transformation can return things that are nil/false-y. (i think the typical pattern here would be
next nil unless some_condition?
)(This block will also be a nice place to rewrite the logic from #154 )