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

Revert "CHECKOUT-8300: Fix config and form field cache by ensuring input parameters are correctly compared" #2618

Merged
merged 1 commit into from
Aug 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 5 additions & 14 deletions packages/core/src/checkout/checkout-action-creator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,11 @@ export default class CheckoutActionCreator {
of(createAction(CheckoutActionType.LoadCheckoutRequested)),
merge(
this._configActionCreator.loadConfig({
...options,
useCache: true,
timeout: options?.timeout,
params: { checkoutId: id },
}),
this._formFieldsActionCreator.loadFormFields({
useCache: true,
timeout: options?.timeout,
params: { ...options?.params, checkoutId: id },
}),
this._formFieldsActionCreator.loadFormFields({ ...options, useCache: true }),
),
defer(() => {
return this._checkoutRequestSender
Expand Down Expand Up @@ -67,14 +64,8 @@ export default class CheckoutActionCreator {
concat(
of(createAction(CheckoutActionType.LoadCheckoutRequested)),
merge(
this._configActionCreator.loadConfig({
useCache: true,
timeout: options?.timeout,
}),
this._formFieldsActionCreator.loadFormFields({
useCache: true,
timeout: options?.timeout,
}),
this._configActionCreator.loadConfig(),
this._formFieldsActionCreator.loadFormFields({ ...options, useCache: true }),
),
defer(async () => {
const state = store.getState();
Expand Down
10 changes: 5 additions & 5 deletions packages/core/src/common/data-store/cache-action.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ describe('cacheAction()', () => {
Promise.resolve(createAction('GET_MESSAGE', `Hello ${name}`)),
);
const subscriber = jest.fn();
const createCachedAction = cacheAction((name, _) =>
const createCachedAction = cacheAction((name) =>
defer(() => getMessage(name) as Promise<Action>),
);

createCachedAction('Foo', { params: { abc: 'abc' } }).subscribe(subscriber);
createCachedAction('Foo', { params: { abc: 'abc' } }).subscribe(subscriber);
createCachedAction('Bar', { params: { abc: 'efg' } }).subscribe(subscriber);
createCachedAction('Bar', { params: { abc: 'efg' } }).subscribe(subscriber);
createCachedAction('Foo').subscribe(subscriber);
createCachedAction('Foo').subscribe(subscriber);
createCachedAction('Bar').subscribe(subscriber);
createCachedAction('Bar').subscribe(subscriber);

await new Promise((resolve) => process.nextTick(resolve));

Expand Down
5 changes: 2 additions & 3 deletions packages/core/src/common/data-store/cache-action.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { Action, ThunkAction } from '@bigcommerce/data-store';
import { memoize } from '@bigcommerce/memoize';
import { isEqual } from 'lodash';
import { from, Observable } from 'rxjs';
import { shareReplay } from 'rxjs/operators';

Expand All @@ -13,13 +12,13 @@ export default function cacheAction<TFunction extends CreateActionFn>(fn: TFunct
}

if (typeof action === 'function') {
return memoize((store) => from(action(store)).pipe(shareReplay()), { isEqual });
return memoize((store) => from(action(store)).pipe(shareReplay()));
}

return action;
}

return memoize(decoratedFn as TFunction, { isEqual });
return memoize(decoratedFn as TFunction);
}

type CreateActionFn = (...args: any[]) => Observable<Action> | ThunkAction<Action> | Action;
10 changes: 2 additions & 8 deletions packages/core/src/config/config-action-creator.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,8 @@ describe('ConfigActionCreator', () => {

it('dispatches actions using cached responses if available', async () => {
const actions = await merge(
configActionCreator.loadConfig({
useCache: true,
params: { checkoutId: '6554a0a0-527f-4d51-9197-58ab22eb1dab' },
}),
configActionCreator.loadConfig({
useCache: true,
params: { checkoutId: '6554a0a0-527f-4d51-9197-58ab22eb1dab' },
}),
configActionCreator.loadConfig({ useCache: true }),
configActionCreator.loadConfig({ useCache: true }),
)
.pipe(toArray())
.toPromise();
Expand Down