Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// Remove moved data from source array
dispatch(
update(oldParentPath, array => {
// TODO clone necessary?
const clonedArray = clone(array);
clonedArray.splice(oldIndex, 1);
console.log(`remove from ${oldParentPath}, index: ${oldIndex}`);
return clonedArray;
})
);
// Add moved data to target array
dispatch(
update(newParentPath, array => {
if (array === undefined || array === null || array.length === 0) {
return [data];
}
// TODO clone necessary?
const clonedArray = clone(array);
clonedArray.splice(newIndex, 0, data);
console.log(`add to ${newParentPath}, index: ${newIndex}`);
return clonedArray;
})
);
return true;
};
remove() {
dispatch(
update(
parentPath,
array => {
const clonedArray = clone(array);
clonedArray.splice(index, 1);
return clonedArray;
}
)
);
},
moveListItem: moveListItem(dispatch)
handleChange: useCallback((path, value) => {
dispatch(update(path, () => value));
}, [dispatch, update])
});
moveDown: (path: string, toMove: number) => (event: any): void => {
event.stopPropagation();
dispatch(
update(path, array => {
moveDown(array, toMove);
return array;
})
);
}
});
add(path, prop, newData) {
dispatch(
update(
Paths.compose(path, prop.property),
array => {
if (_.isEmpty(array)) {
return [newData];
}
array.push(newData);
return array;
}
)
);
}
});
removeItems: (path: string, toDelete: number[]) => (event: any): void => {
event.stopPropagation();
dispatch(
update(path, array => {
toDelete
.sort()
.reverse()
.forEach(s => array.splice(s, 1));
return array;
})
);
},
moveUp: (path: string, toMove: number) => (event: any): void => {
addNewItem(path: string) {
const element = {};
this.props.dispatch(
update(
path,
array => {
if (array === undefined || array === null) {
return [element];
}
const clone = _.clone(array);
clone.push(element);
return clone;
}
)
);
}
add(path, prop, newData) {
dispatch(
update(
Paths.compose(path, prop.property),
array => {
if (_.isEmpty(array)) {
return [newData];
}
array.push(newData);
return array;
}
)
);
}
});
add(path: string, prop: Property, newData: any) {
dispatch(
update(
Paths.compose(path, prop.property),
array => {
if (isEmpty(array)) {
return [newData];
}
array.push(newData);
return array;
}
)
);
}
});