introduce catamorphism for ui components #8812
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
UI Components inductively built upon each other, i.e. components will contain other components.
It is, for some components, possible to access their substructure, but always in a specific manner; there is no generic way to get from the containing component to its children.
Now, @jeph864 is working on Activities and the idea arose to use forms/inputs to publish APIs (see #8746). What's missing right now is a simple way to fold down the inputs into e.g. some json-object, and while at it, this is true for all components.
Therefore, I implemented a mechanism on the componentHelper to walk down the object tree and apply operations to the components, storing the result in a property. This result does not need to stay a component, and you can see its effect quite clearly in the examples included here. Also, modification of the components' instances are perfectly feasible.
Components need to implement
getSubStructure(): array
to participate in the catamorphism; if they don't or return an empty array, recursion just stops and the component is considered a leaf-node.This implementation comes with Container and Field\Group for now, but is explicitely meant for all UI Components.
I fiddled around wit the Panel, e.g., and it behaves just alike.