Skip to content

Commit

Permalink
Include #6261 wp-develop
Browse files Browse the repository at this point in the history
  • Loading branch information
cbravobernal committed Mar 15, 2024
1 parent 042bde1 commit 909aadd
Showing 1 changed file with 29 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -141,20 +141,36 @@ public function config( string $store_namespace, array $config = array() ): arra
* @since 6.5.0
*/
public function print_client_interactivity_data() {
$store = array();
$has_state = ! empty( $this->state_data );
$has_config = ! empty( $this->config_data );
if ( empty( $this->state_data ) && empty( $this->config_data ) ) {
return;
}

$interactivity_data = array();

if ( $has_state || $has_config ) {
if ( $has_config ) {
$store['config'] = $this->config_data;
$config = array();
foreach ( $this->config_data as $key => $value ) {
if ( ! empty( $value ) ) {
$config[ $key ] = $value;
}
if ( $has_state ) {
$store['state'] = $this->state_data;
}
if ( ! empty( $config ) ) {
$interactivity_data['config'] = $config;
}

$state = array();
foreach ( $this->state_data as $key => $value ) {
if ( ! empty( $value ) ) {
$state[ $key ] = $value;
}
}
if ( ! empty( $state ) ) {
$interactivity_data['state'] = $state;
}

if ( ! empty( $interactivity_data ) ) {
wp_print_inline_script_tag(
wp_json_encode(
$store,
$interactivity_data,
JSON_HEX_TAG | JSON_HEX_AMP
),
array(
Expand Down Expand Up @@ -586,8 +602,8 @@ private function data_wp_bind_processor( WP_Interactivity_API_Directives_Process
$result = $this->evaluate( $attribute_value, end( $namespace_stack ), end( $context_stack ) );

if ( null !== $result && (
false !== $result ||
( strlen( $bound_attribute ) > 5 && '-' === $bound_attribute[4] )
false !== $result ||
( strlen( $bound_attribute ) > 5 && '-' === $bound_attribute[4] )
) ) {
/*
* If the result of the evaluation is a boolean and the attribute is
Expand All @@ -597,8 +613,8 @@ private function data_wp_bind_processor( WP_Interactivity_API_Directives_Process
* https://github.com/preactjs/preact/blob/ea49f7a0f9d1ff2c98c0bdd66aa0cbc583055246/src/diff/props.js#L131C24-L136
*/
if (
is_bool( $result ) &&
( strlen( $bound_attribute ) > 5 && '-' === $bound_attribute[4] )
is_bool( $result ) &&
( strlen( $bound_attribute ) > 5 && '-' === $bound_attribute[4] )
) {
$result = $result ? 'true' : 'false';
}
Expand Down

0 comments on commit 909aadd

Please sign in to comment.