feat(32-02): add mixer array comparison helper
- Add mixerArraysEqual helper to compare mixer arrays by ID - Compares master.id + personal.id to create unique pair key - Used to prevent unnecessary Redux dispatches when categorizing mixers
This commit is contained in:
parent
1a42be980c
commit
10a1eb6577
|
|
@ -48,6 +48,29 @@ import { useGlobalContext } from '../context/GlobalContext.js';
|
|||
import { useVuContext } from '../context/VuContext.js';
|
||||
import { getAvatarUrl, getInstrumentIcon45, getInstrumentIcon24 } from '../helpers/utils.js';
|
||||
|
||||
/**
|
||||
* Compare two mixer arrays by their IDs to determine if content changed.
|
||||
* Used to prevent unnecessary Redux dispatches when categorizing mixers.
|
||||
*
|
||||
* @param {Array} prev - Previous mixer array
|
||||
* @param {Array} next - New mixer array
|
||||
* @returns {boolean} True if arrays have same content (by ID)
|
||||
*/
|
||||
const mixerArraysEqual = (prev, next) => {
|
||||
// Same reference = definitely equal
|
||||
if (prev === next) return true;
|
||||
|
||||
// Different lengths = definitely not equal
|
||||
if (!prev || !next || prev.length !== next.length) return false;
|
||||
|
||||
// Compare by mixer pair IDs (master.id + personal.id creates unique pair key)
|
||||
const getIds = (arr) => arr
|
||||
.map(pair => `${pair.master?.id || ''}-${pair.personal?.id || ''}`)
|
||||
.sort()
|
||||
.join(',');
|
||||
|
||||
return getIds(prev) === getIds(next);
|
||||
};
|
||||
|
||||
const useMixerHelper = () => {
|
||||
const dispatch = useDispatch();
|
||||
|
|
|
|||
Loading…
Reference in New Issue