Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function handleUpdateConfig(path: any[], data: any) {
let config = clone(props.config);
if (path.length > 0) {
// Set the new value
const lastItem = path.pop();
let secondLastItem = path.reduce((o, k) => (o[k] = o[k] || {}), config);
if (Array.isArray(secondLastItem)) {
if (data === undefined) secondLastItem.splice(lastItem, 1);
else if (Array.isArray(data)) {
arrayMove.mutate(secondLastItem, lastItem, lastItem + data[0]);
} else if (isObject(data)) {
const newValue = JSON.parse(JSON.stringify(data));
if (!secondLastItem[lastItem]) secondLastItem[lastItem] = [];
secondLastItem[lastItem] = newValue;
}
} else secondLastItem[lastItem] = data;
} else config = data;
props.handleConfigChange!(config);
if (path.find((i: any) => i === 'theme'))
props.handleSetTheme!(config.theme);
}
handleAction(moveSticker, (state, { payload }) => {
arrayMove.mutate(state.order, payload.oldIndex, payload.newIndex);
}),
handleMovePosition = (path, newPos) => {
let config = clone(this.props.config);
const lastItem = path.pop();
let secondLastItem = path.reduce((o, k) => (o[k] = o[k] || {}), config);
arrayMove.mutate(secondLastItem, lastItem, newPos);
this.props.handleConfigChange(config);
this.setState({
editingGroup: undefined,
editingCard: undefined
});
};