Further to my idea to simplify control group creation with states. After giving it a lot of thought here is my proposal.
I would like to propose a small but powerful enhancement to the control schema: the addition of a new conditional key named emptyIf.
This feature would significantly simplify component development, reduce duplication, and make the system more scalable for state-based control groups.
What is emptyIf?
I propose adding a new optional schema key:
“emptyIf”: “condition”
It functions similarly to your existing:
-
visible -
enabled
…using the same expression system and evaluation context.
However, instead of affecting UI visibility or interactivity, emptyIf affects the value a control returns.
Behavior
When emptyIf evaluates to true, the control should return an empty string ("") during output generation.
This does not hide the control in the UI
and does not disable it.
It simply prevents the control from contributing to any final output in rw.props.
Why this matters for developers like me
Groups of controls can exist in multiple states.
Different states naturally require different output patterns.
Today, any component that needs to assemble output from a group of controls must also:
-
replicate portions of the group’s internal state logic
-
understand which controls are applicable in which situations
-
handle conditions that already exist in the schema
-
manually skip controls based on state-dependent logic
This results in:
-
logic duplication
-
hard-to-maintain code
-
greater likelihood of mismatches
-
increased fragility when the platform evolves
By allowing controls to self-declare when they should “fall silent,” the system becomes far easier for developers to reason about, especially for complex, multi-state control groups.
How emptyIf improves extensibility
Keeps logic in one source of truth
Currently, the schema already knows all the conditions.
But hooks must re-express some of those conditions.
emptyIf lets the schema express the final piece:
“In this state, this control should not produce output.”
Components then don’t need duplicated state machines.
Drastically simplifies javascript
With emptyIf in place, a hooks js can generate macros / compiled attributes by simply:
result = allControlOutputs.filter(Boolean).join(" ");
No conditionals.
No branching logic.
No state replication.
Safe, backward-compatible enhancement
-
Existing controls remain unchanged
-
Existing hooks logic continues to work
-
Developers who don’t need this feature can ignore it
-
Component authors who want cleaner output logic can adopt it
Example (generic)
{
"id": "exampleControl",
"format": "example-{{value}}",
"visible": "mode != 'off'",
"emptyIf": "mode == 'off'"
}
This pattern is extremely useful when a group has multiple states where some controls become invisible and should not influence output.
Summary of Benefits
-
Removes state-duplication from hooks
-
Reduces inconsistencies between schema logic and hooks logic
-
Produces cleaner, more maintainable components
-
Increases flexibility for future control types
-
Keeps the system declarative and predictable
-
Requires minimal change to your existing schema system
-
Delivers a large benefit for a small implementation cost