Review feedback: avoid swallowing errors

This commit is contained in:
0BE 2019-12-14 16:19:38 +01:00
parent 6f68437359
commit 2cf2ab00eb

View File

@ -1,23 +1,5 @@
export const isClient = typeof window === 'object';
export const on = (obj: any, ...args: any[]) => {
try {
obj.addEventListener(...args);
} catch (error) {
handleError(error);
}
};
export const on = (obj: any, ...args: any[]) => obj && obj.addEventListener(...args);
export const off = (obj: any, ...args: any[]) => {
try {
obj.removeEventListener(...args);
} catch (error) {
handleError(error);
}
};
const handleError = (error: any) => {
if (process.env.NODE_ENV !== 'production') {
console.error(error);
}
};
export const off = (obj: any, ...args: any[]) => obj && obj.removeEventListener(...args);