You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
42 lines
1.5 KiB
42 lines
1.5 KiB
import { BEGIN_DRAG, PUBLISH_DRAG_SOURCE, HOVER, END_DRAG, DROP, } from '../actions/dragDrop';
|
|
import { ADD_SOURCE, ADD_TARGET, REMOVE_SOURCE, REMOVE_TARGET, } from '../actions/registry';
|
|
import { areArraysEqual } from '../utils/equality';
|
|
import { NONE, ALL } from '../utils/dirtiness';
|
|
import { xor } from '../utils/js_utils';
|
|
export default function dirtyHandlerIds(state = NONE, action) {
|
|
switch (action.type) {
|
|
case HOVER:
|
|
break;
|
|
case ADD_SOURCE:
|
|
case ADD_TARGET:
|
|
case REMOVE_TARGET:
|
|
case REMOVE_SOURCE:
|
|
return NONE;
|
|
case BEGIN_DRAG:
|
|
case PUBLISH_DRAG_SOURCE:
|
|
case END_DRAG:
|
|
case DROP:
|
|
default:
|
|
return ALL;
|
|
}
|
|
const { targetIds = [], prevTargetIds = [] } = action.payload;
|
|
const result = xor(targetIds, prevTargetIds);
|
|
const didChange = result.length > 0 || !areArraysEqual(targetIds, prevTargetIds);
|
|
if (!didChange) {
|
|
return NONE;
|
|
}
|
|
// Check the target ids at the innermost position. If they are valid, add them
|
|
// to the result
|
|
const prevInnermostTargetId = prevTargetIds[prevTargetIds.length - 1];
|
|
const innermostTargetId = targetIds[targetIds.length - 1];
|
|
if (prevInnermostTargetId !== innermostTargetId) {
|
|
if (prevInnermostTargetId) {
|
|
result.push(prevInnermostTargetId);
|
|
}
|
|
if (innermostTargetId) {
|
|
result.push(innermostTargetId);
|
|
}
|
|
}
|
|
return result;
|
|
}
|