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: Improve internal deepMerge function #64879

Merged
merged 11 commits into from
Aug 29, 2024

Conversation

DAreRodz
Copy link
Contributor

@DAreRodz DAreRodz commented Aug 28, 2024

What?

Improves the internal deepMerge() function implementation. The main reason for these changes is to ensure deepMerge() follows the following rules:

  1. It doesn't create signals when manipulating state proxies.
  2. It updates signals only if they exist.
  3. It batches all signal updates together.

Why?

Required by the upcoming getServerState() and getServerContext() functions to handle state updates from the server.

How?

The new deepMerge() implementation directly manipulates the objects behind state proxies. If an existing property value is updated, it checks whether a corresponding PropSignal instance exists. Only in that case are the signal values updated.

Testing Instructions

I added unit tests for the three rules mentioned above.

@DAreRodz DAreRodz added [Type] Enhancement A suggestion for improvement. [Feature] Interactivity API API to add frontend interactivity to blocks. [Packages] Interactivity /packages/interactivity labels Aug 28, 2024
Copy link
Member

@luisherranz luisherranz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks fantastic. Thanks, David! I know you haven't finished yet, but I'm going to approve it anyway.

packages/interactivity/src/proxies/state.ts Outdated Show resolved Hide resolved
packages/interactivity/src/proxies/test/deep-merge.ts Outdated Show resolved Hide resolved
packages/interactivity/src/proxies/state.ts Show resolved Hide resolved
@DAreRodz DAreRodz self-assigned this Aug 29, 2024
@DAreRodz DAreRodz marked this pull request as ready for review August 29, 2024 15:57
Copy link

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: DAreRodz <darerodz@git.wordpress.org>
Co-authored-by: luisherranz <luisherranz@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@DAreRodz
Copy link
Contributor Author

Thanks for the review, @luisherranz! I've addressed your feedback and polished the code a bit. It should be ready now. 🙂

@DAreRodz DAreRodz enabled auto-merge (squash) August 29, 2024 16:00
@DAreRodz DAreRodz merged commit 214b3ca into trunk Aug 29, 2024
62 checks passed
@DAreRodz DAreRodz deleted the refactor/iapi-deep-merge-util branch August 29, 2024 16:31
@github-actions github-actions bot added this to the Gutenberg 19.2 milestone Aug 29, 2024
bph pushed a commit to bph/gutenberg that referenced this pull request Aug 31, 2024
…4879)

* Move deepMerge to proxies and update implementation

* Remove Boolean casting in hasPropSignal implementation

* Test subscriptions to nested props updates

* Remove extraneous label

* Check signals are not created for nested props

* Fix getProxyFromObject types

* Add missing imports

* Add extra assertions to ensure correct signal creation

* Do not expose hasPropSignal from proxies/index

* Add missing TSDocs

* Update changelog

Co-authored-by: DAreRodz <darerodz@git.wordpress.org>
Co-authored-by: luisherranz <luisherranz@git.wordpress.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Interactivity API API to add frontend interactivity to blocks. [Packages] Interactivity /packages/interactivity [Type] Enhancement A suggestion for improvement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants