Clarify Interactivity API evaluate
function and directives to not allow action usage for what should be state
#69269
Labels
Developer Experience
Ideas about improving block and theme developer experience
[Feature] Interactivity API
API to add frontend interactivity to blocks.
[Type] Enhancement
A suggestion for improvement.
This came up as part of working on #68097 in conversation with @luisherranz, specifically in the comments starting with #68097 (review).
Problems to address:
actions
to determine the value for attributes. However, values should always use context or derived state, so this is an anti-pattern that should be more strongly discouraged or even made impossible.evaluate()
function today invokes functions, whereas in relation to the above it should only look up the function and return it, just like it does for regular values.As part of the PR #68097, the behavior was already moved closer towards the right direction, but it's definitely in a temporary state. Here's a list of a few more low-level technical issues that should be ironed out for a proper solution:
evaluate()
needs to check whether the return value is a function and, if so, invoke it. This should be made more ergonomic.data-wp-on
, callbacks like fordata-wp-watch
etc - i.e. functions should never return a value, and thus a negation operator for them is irrelevant.One part that's already prepared for a step in the right direction is that providing a reference to a function in combination with a negation operator will trigger a console warning going forward, since this should never be used, as functions should never be used to return values in the first place. For now it still works due to backward compatibility, but is now deprecated and can eventually be removed.
Let's discuss in this issue what would be a good strategy to get to the end goal. We also need to consider potential in-between steps, such as first deprecating something that is discouraged, launching that in a release, and only later making it impossible.
The text was updated successfully, but these errors were encountered: