Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
elPaths.forEach(elPath => {
const childEl = getExpectedElementAtPath(fixture, elPath);
const elementId = { decoratorId, elPath };
// Component fixture state can be provided before the fixture mounts (eg.
// a previous snapshot of a fixture state or the current fixture state
// from another renderer)
if (!findFixtureStateProps(fixtureState, elementId)) {
const componentName = getComponentName(childEl.type);
setFixtureState(prevFs => ({
...prevFs,
props: createFixtureStateProps({
fixtureState: prevFs,
elementId,
values: createValues(childEl.props),
componentName
})
}));
} else if (
!areNodesEqual(
childEl,
getElementAtPath(prevFixtureRef.current, elPath)
)
) {
return elPaths.reduce((extendedFixture, elPath): React.ReactNode => {
const elementId = { decoratorId, elPath };
const fsProps = findFixtureStateProps(fixtureState, elementId);
return setElementAtPath(extendedFixture, elPath, element => {
if (!fsProps || componentTypeChanged(fsProps.componentName)) {
return {
...element,
key: getElRenderKey(elPath, DEFAULT_RENDER_KEY)
};
}
// Prevent overriding child elements with outdated "children" prop values
// stored in fixture state
// See https://github.com/react-cosmos/react-cosmos/pull/920 for context
const originalProps = element.props;
const extendedProps = extendWithValues(originalProps, fsProps.values);
// HACK alert: Editing React Element by hand
return prevFs => {
const fsProps = findFixtureStateProps(prevFs, elementId);
if (!fsProps) {
const elId = stringifyElementId(elementId);
console.warn(`Trying to update missing element with ID: ${elId}`);
return prevFs;
}
return {
...prevFs,
props: cb(prevFs)
};
};
}
setFixtureState(prevFs => {
const fsProps = findFixtureStateProps(prevFs, elementId);
if (!fsProps) {
console.warn(`Element id ${elementId} no longer exists`);
return prevFs;
}
return {
...prevFs,
props: updateFixtureStateProps({
fixtureState: prevFs,
elementId,
values
})
};
});
};
setFixtureState(fixtureState => {
const fsProps = findFixtureStateProps(fixtureState, elementId);
if (!fsProps) {
console.warn(`Element id ${elementId} no longer exists`);
return fixtureState;
}
const { values } = fsProps;
return {
...fixtureState,
props: updateFixtureStateProps({
fixtureState,
elementId,
values: replaceOrAddItem(values, propVal => propVal.key === key, {
serializable: true,
key,
stringified: value
})