-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Task: Migrate wp-data stores from registerStore to createReduxStore #74399
Comments
Thanks for opening an issue, @noahtallen! I and the rest of @Automattic/team-calypso-frameworks would love to aid with those. Perhaps @sirbrillig and the rest of @Automattic/shilling folks could aid with the checkout-related ones? |
I'm curious: in my testing, while passing the store to |
This is expected, @sirbrillig, because We'll improve the situation with |
Sounds good! I just wanted to make sure I was doing it right! |
Many of the usages of those stores are in Gutenboarding, which I found to be unused. See #74475 where I explain in detail and suggest its removal. Landing that will make part of the work refactoring those stores easier, since some may end up unused. |
I ran into an issue with block-editor-nux (#74454). Essentially, with the way the wp data persistence plugin works, it only works if you use |
In this PR, there are suggestions that using the old registration approach for data stores improves tree shaking. Thoughts? |
I'm not concerned about this for a few reasons:
|
Nice explanation, thanks! One related thought I had is that importing anything from |
That's a valid one, indeed. I don't very much like the idea of re-exporting everything through the main package anyway, especially given that we have side effects. One way to beat that would be to not use a primary
|
The every-store-registration shouldn't be happening. The import * as Foo from './foo';
import * as Bar from './bar';
export { Foo, Bar }; Then webpack will load import { Foo } from 'data-stores'; webpack will not consider the intermediate The caveat is that the import { Foo } from 'data-stores';
registry.select( Foo.store ).getFoo(); |
Nice, thanks for the explanation. This side effect stuff can get tricky :) We are migrating how these stores are used at the same time. Previously, you still needed to import |
Details
The main reason we should do this is that
registerStore
is deprecated. But the main benefit we get is the new approach to using stores gives us much better typescript integration. Previously, one would have to declare types to override the entire wp data package.This is actually impossible to do now that the package provides its own typedefs, so we've had to rely on the temporary solution of casting to selector types like
(select( 'automattic/foo' ) as FooSelectors).selector()
. This is very clunky, and we also lost type info fordispatch
calls. (See this comment for more info.)As a result, we should migrate stores to use the "new" format (it's been available for a long time actually, though it wasn't supported by the WordPress versions we support at first.) And ideally, also start using stores via imports instead of via string names!
This will restore type data we lost in the upgrade, and also make types much easier to work with for WordPress data.
This is all made possible by our recent WordPress package updates done in #73890.
Checklist
A store is registered in each of these files. See PRs for example migrations.
Editing Toolkit Plugin
editing-toolkit-plugin/global-styles/src/store.js
@noahtallen Migrate legacy global styles to register from registerStore #74394apps/editing-toolkit/editing-toolkit-plugin/whats-new/src/store.js
@noahtallen Remove unused data store #74395apps/editing-toolkit/editing-toolkit-plugin/wpcom-block-editor-nav-sidebar/src/store.ts
@noahtallen Migrate wpcom block editor sidebar to create redux store #74396apps/editing-toolkit/editing-toolkit-plugin/starter-page-templates/store.ts
@noahtallen Migrate spt store from registerStore to register #74346Calypso data-stores
packages/data-stores/src/analyzer/index.ts
@tyxla Data Stores: Migrate Analyzer store tocreateReduxStore()
#74414packages/data-stores/src/auth/index.ts
@tyxla Data Stores: Remove unusedauth
store #74418packages/data-stores/src/automated-transfer-eligibility/index.ts
@noahtallen Migrate atomic transfer eligibility store to createReduxStore #74550packages/data-stores/src/domain-suggestions/index.ts
@noahtallen Migrate domain suggestions to create redux store #74551packages/data-stores/src/i18n/index.ts
@tyxla Data Stores: Migrate I18n tocreateReduxStore()
#74427packages/data-stores/src/plans/index.ts
packages/data-stores/src/products-list/index.ts
@tyxla Data Stores: RefactorProductsList
store tocreateReduxStore()
#74566packages/data-stores/src/reader/index.ts
@tyxla Data Stores: Remove unused reader store #74425packages/data-stores/src/subscriber/index.ts
@flootr Data Stores: migrate Subscriber store tocreateReduxStore
#74430packages/data-stores/src/user/index.ts
packages/data-stores/src/wpcom-features/index.ts
@tyxla Data Stores: RefactorWpcomFeatures
store tocreateReduxStore()
#74473packages/data-stores/src/wpcom-plans-ui/index.ts
@tyxla Data Stores: RefactorWpcomPlansUI
store tocreateReduxStore()
#74468.register
instructions once all stores are migrated.Payments related
client/state/partner-portal/credit-card-form/index.ts
@tyxla Data Stores: Refactor partner portal credit card store tocreateReduxStore()
#74656client/my-sites/checkout/composite-checkout/hooks/wpcom-store.ts
Checkout: Migrate checkout data store to createReduxStore #74452client/my-sites/checkout/composite-checkout/payment-methods/netbanking.tsx
client/my-sites/checkout/composite-checkout/payment-methods/paypal.tsx
client/my-sites/checkout/composite-checkout/payment-methods/credit-card/store.ts
client/my-sites/checkout/composite-checkout/payment-methods/wechat/index.tsx
packages/wpcom-checkout/src/payment-methods/alipay.tsx
packages/wpcom-checkout/src/payment-methods/bancontact.tsx
packages/wpcom-checkout/src/payment-methods/eps.tsx
packages/wpcom-checkout/src/payment-methods/giropay.tsx
packages/wpcom-checkout/src/payment-methods/ideal.tsx
packages/wpcom-checkout/src/payment-methods/p24.tsx
packages/wpcom-checkout/src/payment-methods/sofort.tsx
On hold:
These two persist a single option to help keep a modal close. Could probably be migrated to wp preferences.
apps/editing-toolkit/editing-toolkit-plugin/wpcom-block-editor-nux/src/store.js
@noahtallen Migrate block editor nux to createReduxStore #74454apps/editing-toolkit/editing-toolkit-plugin/wpcom-global-styles/store.js
@noahtallen Migrate wpcom global styles to createReduxStore #74500These data stores persist several options. Since these persist much more of the store, it'd be harder to migrate them to wp preferences.
packages/data-stores/src/help-center/index.ts
packages/data-stores/src/launch/index.ts
@tyxla Packages: Remove unused@automattic/launch
package and launch store #75269packages/data-stores/src/onboard/index.ts
packages/data-stores/src/site/index.ts
packages/data-stores/src/stepper-internal/index.ts
Address this after double registration issue is solved:
The text was updated successfully, but these errors were encountered: