Skip to content

Commit

Permalink
MWPW-165303: Fixed potential repetative API calls (#3493)
Browse files Browse the repository at this point in the history
* Fixed potential repetative API calls

* Fixed potential repetative API calls

* Fixed potential repetative API calls

---------

Co-authored-by: Denys Fedotov <dfedotov@Denyss-MacBook-Pro.local>
  • Loading branch information
denlight and Denys Fedotov authored Jan 23, 2025
1 parent b114709 commit 13d8ef0
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion libs/blocks/mmm/mmm.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { fetchData, DATA_TYPE } from '../../features/personalization/personaliza
import { getMepPopup, API_URLS } from '../../features/personalization/preview.js';

const SEARCH_CRITERIA_CHANGE_EVENT = 'mmm-search-change';
let cachedSearchCriteria = '';
export const DEBOUNCE_TIME = 800;

async function toggleDrawer(target, dd, pageId) {
Expand Down Expand Up @@ -319,7 +320,11 @@ async function createPageList(el, search) {

function subscribeToSearchCriteriaChanges() {
document.addEventListener(SEARCH_CRITERIA_CHANGE_EVENT, (el) => {
createPageList(document.querySelector('.mmm').parentNode, el.detail);
const searchCriteria = JSON.stringify(el?.detail || {});
if (cachedSearchCriteria !== searchCriteria) {
createPageList(document.querySelector('.mmm').parentNode, el.detail);
cachedSearchCriteria = searchCriteria;
}
});
}

Expand Down

0 comments on commit 13d8ef0

Please sign in to comment.