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

fix(atomic): replace set polyfill in-house for size optimization #4550

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
12 changes: 0 additions & 12 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion packages/atomic/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@
"@popperjs/core": "^2.11.6",
"@salesforce-ux/design-system": "^2.16.1",
"@stencil/store": "2.0.16",
"core-js": "3.37.1",
"dayjs": "1.11.12",
"dompurify": "3.1.6",
"escape-html": "1.0.3",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
ProductTemplatesHelpers,
} from '@coveo/headless/commerce';
import {h} from '@stencil/core';
import 'core-js/actual/set';
import {intersection} from '../../../utils/set';
import {aggregate, isElementNode, isVisualNode} from '../../../utils/utils';
import {ItemTarget} from '../../common/layout/display-options';
import {isResultSectionNode} from '../../common/layout/sections';
Expand Down Expand Up @@ -179,7 +179,7 @@ export function makeMatchConditions(
if (mustNotMatch[field]) {
const mustNotMatchValues = new Set(mustNotMatch[field]);
const mustMatchValues = new Set(mustMatch[field]);
const commonValues = mustMatchValues.intersection(mustNotMatchValues);
const commonValues = intersection(mustNotMatchValues, mustMatchValues);
if (commonValues.size > 0) {
console.error(
`Conflicting match conditions for field ${field}, the template will be ignored.`,
Expand Down
10 changes: 10 additions & 0 deletions packages/atomic/src/utils/set.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// TODO: Replace by Set.prototype.intersection in July 2025
export function intersection<T>(setA: Set<T>, setB: Set<T>): Set<T> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where did you take the implementation?

Shouldn't we unit-test it if it's in-house?

const result = new Set<T>();
for (const elem of setA) {
if (setB.has(elem)) {
result.add(elem);
}
}
return result;
}
2 changes: 1 addition & 1 deletion packages/atomic/tsconfig.stencil.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"allowSyntheticDefaultImports": true,
"declaration": false,
"experimentalDecorators": true,
"lib": ["dom", "ES2023", "ESNext.Collection"],
"lib": ["dom", "ES2023"],
"moduleResolution": "Bundler",
"module": "ES2022",
"target": "ES2021",
Expand Down
Loading