RFC: What's best way to expose registerProductCollection
for 3PDs?
#47345
Replies: 3 comments 6 replies
-
Thanks, @imanish003, for kicking off this discussion! I agree entirely with you and I think that we should follow the first approach.
IMHO, I think that we should create another package. This package should contain only code that we want to expose to 3rd party developers to avoid any potential risk that we make some APIs/functions public involuntarily. Also, on long term, it would be great if this package would be full-typed and published on npm. In this way, even if it will be extracted by For example |
Beta Was this translation helpful? Give feedback.
-
+1 to exposing a function like
Something we could evaluate in the future is whether it would make sense to merge these two packages, the new one we create and |
Beta Was this translation helpful? Give feedback.
-
I'm also in favor of option 1. A few arguments:
There is certainly much room for improvement in terms of the organization of these packages, but I personally see the Also
I don't particularly see this as a con. Using this package, 3PDs can:
Above all, remember that this should also provide much simpler access to this helper by calling directly wc.blocksRegistry.__experimentalRegisterProductCollection ({...}) without even the need for Webpack. |
Beta Was this translation helpful? Give feedback.
-
Introduction
We are planning to expose
__experimentalRegisterProductCollection
, which will be called like this:At this stage, let's set aside the specifics of the function's parameters. The primary goal here is to facilitate both 3PDs and us in registering new collections. A key consideration now is how best to make this function available to 3PDs. Here are a couple of options:
1. Expose a function like
__experimentalRegisterProductCollection
One potential method is using a package similar to how plugins utilize
registerCheckoutBlock
from the@woocommerce/blocks-checkout
package:If we decide on this approach, we need to determine the most appropriate package for distribution or create a new package. Currently, functions related to cart and checkout are packaged under
@woocommerce/blocks-checkout
. Here are the packages available in the WooCommerce repository as you can see here:Question: Which package is most suitable for integrating the
__experimentalRegisterProductCollection
function?@woocommerce/blocks-components
to expose__experimentalRegisterProductCollection
. AFAIU, It's only used by Cart & Checkout blocks to expose reusable components. Alternatively,@woocommerce/blocks-registry
, which houses various register-type functions, might also be suitable (Thanks @xristos3490 for pointing this out). Your insights on this would be greatly valued.Note
It is worth noting that some packages, like
@woocommerce/blocks-components
, are not published on NPM. They are only accessible to 3PDs through the @woocommerce/dependency-extraction-webpack-plugin in a Webpack configuration.Pros
Cons
It will require Webpack Configuration by 3PDs through the @woocommerce/dependency-extraction-webpack-plugin.Based on this comment by @xristos3490, this isn't a con. I am updating it just to keep it up to date.2. Using JS filter
Another approach is to expose a JavaScript filter for 3PDs to add new collections. Here is a quick example:
Pros
Cons
Need Feedback
I am leaning towards the first method of exposing the
__experimentalRegisterProductCollection
function. It would be beneficial to gain a better understanding of the purpose of each existing package and consider establishing a dedicated package for Woo blocks. To date, only cart and checkout blocks have offered these types of extensibility points. Now, it's time to make a decision for other WooCommerce blocks. I look forward to feedback on whether it's advisable to use the existing packages or if we should create a new one for__experimentalRegisterProductCollection
function.Beta Was this translation helpful? Give feedback.
All reactions