I have a function that does the same thing under 2 difference circumstances inside of if statement but the function has been called in a different module ? what is the best way to handle the issue I mean I could export the function and import it to the other module but I don't like the idea that I have to call the function ... is there any better design pattern ?
// Module
if(somthing is true){
const functionSave =()=>{
// function logic
}
functionSave()
}
const saveFile = () => {
if (_miscContext.modal.group === 'a') {
// change file privlige
localStorage.setItem('user', JSON.stringify('a'));
}
const ls = JSON.stringify(localStorage);
const downloadBlob = (fileName: string, blob: any) => {
const link = document.createElement('a');
link.href = URL.createObjectURL(blob);
link.target = '_blank';
link.download = fileName;
document.body.appendChild(link);
link.click();
};
const blob = new Blob([ls], {
type: 'text',
});
if (_miscContext.modal.group === 'a' || !_miscContext.modal.group) {
downloadBlob('test', blob);
} else if (_miscContext.modal.group === 'b') {
downloadBlob(`test2`, blob);
}
// Tracking dowload
ReactGA.event({
category: 'Click',
action: 'Saving File',
});
_miscContext.SetModal(false, '', 'preference');
if (_miscContext.modal.group === 'a') {
localStorage.setItem('user', JSON.stringify('defualt'));
}
return;
};