Skip to content
This repository was archived by the owner on Nov 9, 2024. It is now read-only.

Commit 681e7cf

Browse files
authored
fix: unique util (#292)
1 parent ac61324 commit 681e7cf

File tree

3 files changed

+25
-18
lines changed

3 files changed

+25
-18
lines changed

src/Tippy.js

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -141,16 +141,6 @@ export default function TippyGenerator(tippy) {
141141

142142
const {instance} = mutableBox;
143143

144-
if (
145-
instance.props.popperOptions?.modifiers?.find(
146-
i => i.name === '$$tippyReact',
147-
)
148-
) {
149-
console.log(
150-
deepPreserveProps(instance.props, computedProps).popperOptions,
151-
);
152-
}
153-
154144
instance.setProps(deepPreserveProps(instance.props, computedProps));
155145

156146
// Fixes #264

src/utils.js

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,17 +32,16 @@ export function toDataAttributes(attrs) {
3232
return dataAttrs;
3333
}
3434

35-
export function uniqueByName(arrNaturalOrder) {
35+
export function uniqueByShape(arr) {
3636
const output = [];
3737
const lookup = Object.create(null);
38-
const arr = arrNaturalOrder.reverse();
3938

40-
for (const item in arr) {
41-
if (lookup[arr[item].name] === undefined) {
42-
output.push(arr[item]);
39+
arr.forEach(item => {
40+
if (lookup[JSON.stringify(item)] === undefined) {
41+
output.push(item);
4342
}
44-
lookup[arr[item].name] = arr[item];
45-
}
43+
lookup[JSON.stringify(item)] = true;
44+
});
4645

4746
return output;
4847
}
@@ -53,7 +52,7 @@ export function deepPreserveProps(instanceProps, componentProps) {
5352
popperOptions: {
5453
...instanceProps.popperOptions,
5554
...componentProps.popperOptions,
56-
modifiers: uniqueByName([
55+
modifiers: uniqueByShape([
5756
...(instanceProps.popperOptions?.modifiers || []),
5857
...(componentProps.popperOptions?.modifiers || []),
5958
]),

test/utils.test.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import {uniqueByShape} from '../src/utils';
2+
3+
describe('uniqueByShape', () => {
4+
it('filters duplicates', () => {
5+
expect(
6+
uniqueByShape([
7+
{name: 'hello'},
8+
{name: 'hello'},
9+
{name: 'hello', enabled: false},
10+
{name: 'hello2'},
11+
]),
12+
).toEqual([
13+
{name: 'hello'},
14+
{name: 'hello', enabled: false},
15+
{name: 'hello2'},
16+
]);
17+
});
18+
});

0 commit comments

Comments
 (0)