Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Interactivity API: Implement wp_initial_state() #56698

Closed
wants to merge 28 commits into from

Conversation

DAreRodz
Copy link
Contributor

@DAreRodz DAreRodz commented Nov 30, 2023

⚠️ This PR was superseded by #57556 as recent changes in the server directive processing code created merge conflicts that were hard to solve and time-consuming.

What?

Built on top of #56302
Tracking issue: #53740

Implements the wp_initial_state() function, a replacement for wp_store(), following the specification defined in the new store() API proposal. Extracted from the proposal:

If we move the derived state to the state property, there's no need to use the long wp_store format anymore: the state property can be absorbed in the function name (wp_initial_state) and the namespace can be passed as a string.

Instead of this:

wp_store( array(
  'state' => array(
    'myPlugin' => array(
      'someValue'  => 'some value',
      'someNumber' => 123,
    ),
  ),
  'selectors' => array(
    'myPlugin' => array(
      'someDerivedValue' => 'some derived value',
    ),
  ),
) );

We can write this and it will have the same information:

wp_initial_state( 'myPlugin', array(
  'someValue'        => 'some value',
  'someNumber'       => 123,
  'someDerivedValue' => 'some derived value',
) );

In addition, a system to handle store namespaces was added as required by wp_initial_state.

Why?

This function simplifies the way the initial state for interactive blocks is defined. Also, it is required to complete the migration to the new store() API.

How?

WIP

Testing Instructions

TBD

Copy link

This pull request has changed or added PHP files. Please confirm whether these changes need to be synced to WordPress Core, and therefore featured in the next release of WordPress.

If so, it is recommended to create a new Trac ticket and submit a pull request to the WordPress Core Github repository soon after this pull request is merged.

If you're unsure, you can always ask for help in the #core-editor channel in WordPress Slack.

Thank you! ❤️

View changed files
❔ lib/experimental/interactivity-api/class-wp-interactivity-initial-state.php
❔ lib/experimental/interactivity-api/directives/wp-interactive.php
❔ lib/experimental/interactivity-api/initial-state.php
❔ phpunit/experimental/interactivity-api/class-wp-interactivity-initial-state-test.php
❔ lib/experimental/interactivity-api/class-wp-directive-processor.php
❔ lib/experimental/interactivity-api/directive-processing.php
❔ lib/experimental/interactivity-api/directives/wp-bind.php
❔ lib/experimental/interactivity-api/directives/wp-class.php
❔ lib/experimental/interactivity-api/directives/wp-context.php
❔ lib/experimental/interactivity-api/directives/wp-style.php
❔ lib/experimental/interactivity-api/directives/wp-text.php
❔ lib/load.php
❔ phpunit/experimental/interactivity-api/directive-processing-test.php
❔ phpunit/experimental/interactivity-api/directives/wp-bind-test.php
❔ phpunit/experimental/interactivity-api/directives/wp-class-test.php
❔ phpunit/experimental/interactivity-api/directives/wp-context-test.php
❔ phpunit/experimental/interactivity-api/directives/wp-style-test.php
❔ phpunit/experimental/interactivity-api/directives/wp-text-test.php

@luisherranz luisherranz changed the base branch from trunk to update/interactivity-mark-interactive-parts December 4, 2023 12:06
@cbravobernal cbravobernal force-pushed the update/interactivity-mark-interactive-parts branch 2 times, most recently from 16e5150 to 1ed8b04 Compare December 4, 2023 17:18
@cbravobernal cbravobernal force-pushed the update/interactivity-mark-interactive-parts branch 2 times, most recently from af9e04c to a3f5aa7 Compare December 13, 2023 23:27
@cbravobernal cbravobernal force-pushed the update/interactivity-mark-interactive-parts branch from ec22d09 to 4843cb7 Compare December 26, 2023 14:34
Base automatically changed from update/interactivity-mark-interactive-parts to trunk December 28, 2023 12:24
@DAreRodz
Copy link
Contributor Author

DAreRodz commented Jan 4, 2024

⚠️ This PR was superseded by #57556. Development continues there. 🙂

@DAreRodz DAreRodz closed this Jan 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants