From ce461d8f3735deaef7427de6b94ec4db87b2c428 Mon Sep 17 00:00:00 2001 From: Marin Atanasov <8436925+tyxla@users.noreply.github.com> Date: Fri, 24 Jun 2022 10:29:19 +0300 Subject: [PATCH] Lodash: Remove completely from notices package (#41834) --- package-lock.json | 3 +-- packages/notices/package.json | 3 +-- packages/notices/src/store/actions.js | 9 +++------ packages/notices/src/store/reducer.js | 9 ++------- 4 files changed, 7 insertions(+), 17 deletions(-) diff --git a/package-lock.json b/package-lock.json index 82434f8fabb659..953ba0b9ec153e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -17507,8 +17507,7 @@ "requires": { "@babel/runtime": "^7.16.0", "@wordpress/a11y": "file:packages/a11y", - "@wordpress/data": "file:packages/data", - "lodash": "^4.17.21" + "@wordpress/data": "file:packages/data" } }, "@wordpress/npm-package-json-lint-config": { diff --git a/packages/notices/package.json b/packages/notices/package.json index c03c126a6719b5..25a2e6281e26e3 100644 --- a/packages/notices/package.json +++ b/packages/notices/package.json @@ -27,8 +27,7 @@ "dependencies": { "@babel/runtime": "^7.16.0", "@wordpress/a11y": "file:../a11y", - "@wordpress/data": "file:../data", - "lodash": "^4.17.21" + "@wordpress/data": "file:../data" }, "peerDependencies": { "react": "^17.0.0" diff --git a/packages/notices/src/store/actions.js b/packages/notices/src/store/actions.js index 1574f85b3b6421..f4bf7c31d23f67 100644 --- a/packages/notices/src/store/actions.js +++ b/packages/notices/src/store/actions.js @@ -1,8 +1,3 @@ -/** - * External dependencies - */ -import { uniqueId } from 'lodash'; - /** * Internal dependencies */ @@ -19,6 +14,8 @@ import { DEFAULT_CONTEXT, DEFAULT_STATUS } from './constants'; * */ +let uniqueId = 0; + /** * Returns an action object used in signalling that a notice is to be created. * @@ -54,7 +51,7 @@ export function createNotice( status = DEFAULT_STATUS, content, options = {} ) { speak = true, isDismissible = true, context = DEFAULT_CONTEXT, - id = uniqueId( context ), + id = `${ context }${ ++uniqueId }`, actions = [], type = 'default', __unstableHTML, diff --git a/packages/notices/src/store/reducer.js b/packages/notices/src/store/reducer.js index ca68877d8d09e9..ff2359b61cc013 100644 --- a/packages/notices/src/store/reducer.js +++ b/packages/notices/src/store/reducer.js @@ -1,8 +1,3 @@ -/** - * External dependencies - */ -import { reject } from 'lodash'; - /** * Internal dependencies */ @@ -22,12 +17,12 @@ const notices = onSubKey( 'context' )( ( state = [], action ) => { case 'CREATE_NOTICE': // Avoid duplicates on ID. return [ - ...reject( state, { id: action.notice.id } ), + ...state.filter( ( { id } ) => id !== action.notice.id ), action.notice, ]; case 'REMOVE_NOTICE': - return reject( state, { id: action.id } ); + return state.filter( ( { id } ) => id !== action.id ); } return state;