Skip to content
This repository has been archived by the owner on Feb 23, 2024. It is now read-only.

Commit

Permalink
add namespace to Interactivity API
Browse files Browse the repository at this point in the history
  • Loading branch information
gigitux committed Aug 18, 2023
1 parent de5c3e0 commit 04e953f
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 18 deletions.
3 changes: 2 additions & 1 deletion src/BlockTypes/ProductButton.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
namespace Automattic\WooCommerce\Blocks\BlockTypes;

use Automattic\WooCommerce\Blocks\Utils\StyleAttributesUtils;
use Automattic\WooCommerce\Blocks\Interactivity\WC_Interactivity_Store;

/**
* ProductButton class.
Expand Down Expand Up @@ -107,7 +108,7 @@ protected function render( $attributes, $content, $block ) {
)
);

wc_store(
WC_Interactivity_Store::wc_store(
array(
'state' => array(
'woocommerce' => array(
Expand Down
21 changes: 18 additions & 3 deletions src/Interactivity/class-wc-interactivity-store.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
<?php
namespace Automattic\WooCommerce\Blocks\Interactivity;

/**
* Manages the initial state of the Interactivity API store in the server and
* its serialization so it can be restored in the browser upon hydration.
*
* It's a private class, exposed by other functions, like `wc_store`.
*
* @access private
*/
class WC_Interactivity_Store {
/**
Expand All @@ -20,7 +21,7 @@ class WC_Interactivity_Store {
*
* @return array
*/
static function get_data() {
static private function get_data() {
return self::$store;
}

Expand All @@ -29,7 +30,7 @@ static function get_data() {
*
* @param array $data The data that will be merged with the exsisting store.
*/
static function merge_data( $data ) {
static private function merge_data( $data ) {
self::$store = array_replace_recursive( self::$store, $data );
}

Expand All @@ -40,6 +41,20 @@ static function reset() {
self::$store = array();
}

/**
* Merge data with the exsisting store.
*
* @param array $data Data that will be merged with the exsisting store.
*
* @return $data The current store data.
*/
static public function wc_store($data) {
if ( $data ) {
self::merge_data( $data );
}
return self::get_data();
}

/**
* Render the store data.
*/
Expand Down
14 changes: 0 additions & 14 deletions src/Interactivity/store.php
Original file line number Diff line number Diff line change
@@ -1,18 +1,4 @@
<?php
/**
* Merge data with the exsisting store.
*
* @param array $data Data that will be merged with the exsisting store.
*
* @return $data The current store data.
*/
function wc_store( $data = null ) {
if ( $data ) {
WC_Interactivity_Store::merge_data( $data );
}
return WC_Interactivity_Store::get_data();
}

/**
* Render the Interactivity API store in the frontend.
*/
Expand Down

0 comments on commit 04e953f

Please sign in to comment.