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

Move createCartHandler's customMethods__unstable to stable #1440

Merged
merged 8 commits into from Oct 25, 2023
5 changes: 5 additions & 0 deletions .changeset/shy-jokes-flow.md
@@ -0,0 +1,5 @@
---
'@shopify/hydrogen': patch
---

Move `createCartHandler`'s `customMethods__unstable` to stable
Expand Up @@ -11,11 +11,13 @@ const cartQueryOptions = {
getCartId: cartGetIdDefault(request.headers),
};

const getCartId = cartGetIdDefault(request.headers);

const cart = createCartHandler({
storefront,
getCartId: cartGetIdDefault(request.headers),
getCartId,
setCartId: cartSetIdDefault(),
customMethods__unstable: {
customMethods: {
editInLine: async (addLines, removeLineIds, optionalParams) => {
// Using Hydrogen default cart query methods
await cartLinesAddDefault(cartQueryOptions)(addLines, optionalParams);
Expand All @@ -28,7 +30,7 @@ const cart = createCartHandler({
// With your own Storefront API graphql query
return await storefront.mutate(CART_LINES_ADD_MUTATION, {
variables: {
id: optionalParams.cartId,
id: optionalParams.cartId || getCartId(),
lines,
},
});
Expand Down
6 changes: 3 additions & 3 deletions packages/hydrogen/src/cart/createCartHandler.test.ts
Expand Up @@ -10,7 +10,7 @@ type MockCarthandler = {
cartId?: string;
cartQueryFragment?: string;
cartMutateFragment?: string;
customMethods__unstable?: Record<string, Function>;
customMethods?: Record<string, Function>;
};

function getCartHandler(options: MockCarthandler = {}) {
Expand Down Expand Up @@ -51,7 +51,7 @@ describe('createCartHandler', () => {
storefront: mockCreateStorefrontClient(),
getCartId: () => undefined,
setCartId: () => new Headers(),
customMethods__unstable: {
customMethods: {
foo() {
return 'bar';
},
Expand All @@ -65,7 +65,7 @@ describe('createCartHandler', () => {

it('can override default methods', async () => {
const cart = getCartHandler({
customMethods__unstable: {
customMethods: {
get() {
return Promise.resolve('bar');
},
Expand Down
8 changes: 4 additions & 4 deletions packages/hydrogen/src/cart/createCartHandler.ts
Expand Up @@ -57,7 +57,7 @@ export type CustomMethodsBase = Record<string, Function>;
export type CartHandlerOptionsWithCustom<
TCustomMethods extends CustomMethodsBase,
> = CartHandlerOptions & {
customMethods__unstable?: TCustomMethods;
customMethods?: TCustomMethods;
};

export type HydrogenCart = {
Expand Down Expand Up @@ -167,10 +167,10 @@ export function createCartHandler<TCustomMethods extends CustomMethodsBase>(
deleteMetafield: cartMetafieldDeleteDefault(mutateOptions),
};

if ('customMethods__unstable' in options) {
if ('customMethods' in options) {
return {
...methods,
...(options.customMethods__unstable ?? {}),
...(options.customMethods ?? {}),
};
} else {
return methods;
Expand Down Expand Up @@ -206,7 +206,7 @@ export type CartHandlerOptionsForDocs<
* Define custom methods or override existing methods for your cart API instance.
* See the [example usage](/docs/api/hydrogen/2023-10/utilities/createcarthandler#example-custom-methods) in the documentation.
*/
customMethods__unstable?: TCustomMethods;
customMethods?: TCustomMethods;
};

export type HydrogenCartForDocs = {
Expand Down
2 changes: 1 addition & 1 deletion packages/hydrogen/src/product/VariantSelector.test.ts
Expand Up @@ -3,7 +3,7 @@ import {createElement} from 'react';
import {cleanup, render} from '@testing-library/react';
import {describe, it, expect, afterEach, vi, afterAll} from 'vitest';
import {type LinkProps, useLocation} from '@remix-run/react';
import {ProductVariant} from '@shopify/hydrogen-react/storefront-api-types';
import type {ProductVariant} from '@shopify/hydrogen-react/storefront-api-types';

vi.mock('@remix-run/react', () => ({
useNavigation: vi.fn(() => ({
Expand Down