in packages/eui/scripts/jest/polyfills/mutation_observer.js [300:340]
var _resolveConflicts = function (conflicts, node, $kids, $oldkids, numAddedNodes) {
// the distance between the first conflicting node and the last
var distance = conflicts.length - 1;
// prevents same conflict being resolved twice consider when two nodes switch places.
// only one should be given a mutation event (note -~ is used as a math.ceil shorthand)
var counter = -~((distance - numAddedNodes) / 2);
var $cur;
var oldstruct;
var conflict;
while ((conflict = conflicts.pop())) {
$cur = $kids[conflict.i];
oldstruct = $oldkids[conflict.j];
// attempt to determine if there was node rearrangement... won't gaurentee all matches
// also handles case where added/removed nodes cause nodes to be identified as conflicts
if (config.kids && counter && Math.abs(conflict.i - conflict.j) >= distance) {
mutations.push(new MutationRecord({
type: 'childList',
target: node,
addedNodes: [$cur],
removedNodes: [$cur],
// haha don't rely on this please
nextSibling: $cur.nextSibling,
previousSibling: $cur.previousSibling
}));
counter--; // found conflict
}
// Alright we found the resorted nodes now check for other types of mutations
if (config.attr && oldstruct.attr)
_this.findAttributeMutations(mutations, $cur, oldstruct.attr, config.afilter);
if (config.charData && $cur.nodeType === 3 && $cur.nodeValue !== oldstruct.charData) {
mutations.push(new MutationRecord({
type: 'characterData',
target: $cur,
oldValue: oldstruct.charData
}));
}
// now look @ subtree
if (config.descendents)
_findMutations($cur, oldstruct);
}
};