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

CRUD: populates store when a new item is created #47627

Closed
Tracked by #47622
retrofox opened this issue May 20, 2024 · 0 comments · Fixed by #47632
Closed
Tracked by #47622

CRUD: populates store when a new item is created #47627

retrofox opened this issue May 20, 2024 · 0 comments · Fixed by #47632
Assignees
Labels
package: @woocommerce/data issues related to @woocommerce/data team: Mothra

Comments

@retrofox
Copy link
Contributor

retrofox commented May 20, 2024

The key to our strategy for updating the store optimistically is understanding the data structure in advance. This allows us to populate the store precisely when a new item is created, anticipating its shape.

Let's examine the Attribute Terms store (/wc/admin/products/attributes/terms):

Screenshot 2024-05-20 at 15 56 33

The image above shows the status of the store. It has four items:

  • data: contains the raw data
  • items: links the GET_ITEMS indexes with the raw data used by the selectors.
  • itemsCounts: it computes the number of items based on the data. It's used by counter-selectors

Now, let's suppose a new item is created, the response has the following shape:

{
  "id": 600,
  "name": "pink",
  "slug": "pink",
  "description": "",
  "menu_order": 0,
  "count": 0,
}

Currently, when a new item is created, it's added to the store's data key. However, the items and itemsCounts keys are not updated. To address this, we need to update the implementation of these properties without triggering a new sync request (invalidate resolution).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
package: @woocommerce/data issues related to @woocommerce/data team: Mothra
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant