You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
With the deprecation of the method pick_child_condition, I have a usecase I'm not sure how to do anymore.
I have a component that is marked as fallthrough, and that itself should be a fallthrough component (with its condition() == false when none of its children have anything to show.
I had the following (brittle I know) condition:
-- NOTE: We need a condition function to be properly skipped when pick_child_on_condition is-- used on the block that calls us.condition=function(self)
hline_utils.pick_child_on_condition(self)
-- NOTE: pick_child_on_condition fills the `self.pick_child` table when one of the condition-- is truthy, when that table is empty, no children matched and the entire block should be-- skipped.returnnotvim.tbl_isempty(self.pick_child)
end,
So with the new fallthrough marker, could we have a function to know if a child is going to be displayed or not?
Or maybe there is a better solution ?
I've currently replicated the behavior I want with:
The text was updated successfully, but these errors were encountered:
bew
changed the title
Make a block with ONLY fallthrough children? (was possible before pick_child_condition depreciation)
Make a block with ONLY fallthrough children?
Aug 31, 2022
Your solution is doing almost exactly what pick_pick_on_condition implemented. However this is inefficient, as we are calculating all of the children conditions ahead to chose the child, and then its condition is going to be evaluated again. Doing this in the parent's condition is also risky, if for some reason the children condition needs to know something that would be computed in the parent's init.
The best way to solve this is to remove the conditions from the children, and put them explicitly in the parent init (or condition if the parent itself is part of a nofallfhrough block), which would then set pick_child accordingly. If the parent has no provider, then the block will remain silent if all conditions fail, otherwise you'll need to set a flag that will tell the provider function whether to return something or not.
I hope I understood your problem and the you found my answer useful, I'll write up an example tomorrow.
If I misunderstood something, please write a small example describing the behavior you're trying to achieve
With the deprecation of the method
pick_child_condition
, I have a usecase I'm not sure how to do anymore.I have a component that is marked as fallthrough, and that itself should be a fallthrough component (with its
condition() == false
when none of its children have anything to show.I had the following (brittle I know) condition:
So with the new
fallthrough
marker, could we have a function to know if a child is going to be displayed or not?Or maybe there is a better solution ?
I've currently replicated the behavior I want with:
Maybe this could be a builtin function?
The text was updated successfully, but these errors were encountered: