-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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()
#57556
Interactivity API: Implement wp_initial_state()
#57556
Conversation
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 |
// TODO: Do not pass the store as argument. Implement something similar | ||
// to what we have in the JS runtime (`getContext()`, etc.). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@luisherranz, do you remember the idea we had for computing the derived state in the server? I added this comment just in case we want to change the current implementation (I'm pretty sure we want). 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's remove support for closures for now.
Implement wp_initial_state()
wp_initial_state()
I added a small commit to prevent md5 and serializing when comparing blocks that are clearly not root.
Feel free to revert in case you consider is better to wait for the PR to be merged. |
lib/experimental/interactivity-api/class-wp-interactivity-initial-state.php
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Everything looks good to me 🎉 🎉
Has this been backported to Core already? |
Was refactored - backported here: |
What?
Supersedes #56698
Tracking issue: #56803
Implements the
wp_initial_state()
function, a replacement forwp_store()
, following the specification defined in the newstore()
API proposal. Extracted from the proposal: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?
This PR implements the following:
WP_Interactivity_Initial_State
―a class with static properties and methods to handle the Interactivity API initial state globally.wp_initial_state()
―a function that abstracts the usage of the aforementioned class.data-wp-interactive
directive.data-wp-text="custom-ns::state.prop"
.Considerations
I think we could address the following items in subsequent PRs:
wp_initial_state()
#57556 (comment)). We need to think of a way to add support again without passing anything as an argument, similar to what is done in the Interactivity API JS runtime.WP_Interactivity_Initial_State
could be refactored to implement a singleton pattern instead of using static methods (if necessary).