31 lines
1.0 KiB
JavaScript
31 lines
1.0 KiB
JavaScript
import { mergeChildMappings } from './mergeChildMappings';
|
|
export function getNextChildMapping(prevChildMapping, nextChildMapping) {
|
|
const childrenMapping = mergeChildMappings(prevChildMapping, nextChildMapping);
|
|
Object.entries(childrenMapping).forEach(([key, childDefinition])=>{
|
|
const hasPrev = key in prevChildMapping;
|
|
const hasNext = key in nextChildMapping;
|
|
if (hasNext) {
|
|
// Case 1: item hasn't changed transition states
|
|
if (hasPrev) {
|
|
childrenMapping[key] = {
|
|
...childDefinition
|
|
};
|
|
return;
|
|
}
|
|
// Case 2: item is new (entering)
|
|
childrenMapping[key] = {
|
|
...childDefinition,
|
|
appear: true,
|
|
visible: true
|
|
};
|
|
return;
|
|
}
|
|
// Case 3: item is leaving
|
|
childrenMapping[key] = {
|
|
...childDefinition,
|
|
visible: false
|
|
};
|
|
});
|
|
return childrenMapping;
|
|
}
|