Skip to content

Commit

Permalink
Lodash: Refactor away from _.uniqWith() (WordPress#41812)
Browse files Browse the repository at this point in the history
  • Loading branch information
tyxla authored Jun 22, 2022
1 parent d86eaa4 commit 0f97e8d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ module.exports = {
'take',
'toString',
'trim',
'uniqWith',
],
message:
'This Lodash method is not recommended. Please use native functionality instead. If using `memoize`, please use `memize` instead.',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
* External dependencies
*/
import { View, Text, TouchableWithoutFeedback } from 'react-native';
import { uniqWith } from 'lodash';

/**
* WordPress dependencies
Expand All @@ -23,12 +22,17 @@ import { Icon, plusCircleFilled } from '@wordpress/icons';
*/
import styles from './styles.scss';

const isMediaEqual = ( media1, media2 ) =>
media1.id === media2.id || media1.url === media2.url;

// Remove duplicates after gallery append.
const dedupMedia = ( media ) =>
uniqWith(
media,
( media1, media2 ) =>
media1.id === media2.id || media1.url === media2.url
media.reduce(
( dedupedMedia, mediaItem ) =>
dedupedMedia.some( ( item ) => isMediaEqual( item, mediaItem ) )
? dedupedMedia
: [ ...dedupedMedia, mediaItem ],
[]
);

function MediaPlaceholder( props ) {
Expand Down

0 comments on commit 0f97e8d

Please sign in to comment.